Sign in to follow this  
MadsGustaf

what does the '-' operator do?

Recommended Posts

as the topic title says,what do the '->' operator do? example:
[source lang = "cpp"] 
if (!GameEngine::GetEngine() -> GetSleep())

what do it do in this coincidence? thanks in advance!

Share this post


Link to post
Share on other sites
Quote:
Original post by MadsGustaf
as the topic title says,what do the '->' operator do?
example:

*** Source Snippet Removed ***
what do it do in this coincidence?

thanks in advance!


If GameEngine::GetEngine() returns a pointer to a class, operator-> is used to access members of this class (in this specific case, it will access the GetSleep() member, so in turn the GetSleep() method will be called).

I suggest you to read some book about the C++ language - many great books exist (Accelerated C++ is one example), and you'll learn enough of the syntax to understand code like this.

Regards,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
Quote:
Original post by MadsGustaf
as the topic title says,what do the '->' operator do?
example:

*** Source Snippet Removed ***
what do it do in this coincidence?

thanks in advance!


If GameEngine::GetEngine() returns a pointer to a class, operator-> is used to access members of this class (in this specific case, it will access the GetSleep() member, so in turn the GetSleep() method will be called).

I suggest you to read some book about the C++ language - many great books exist (Accelerated C++ is one example), and you'll learn enough of the syntax to understand code like this.

Regards,


i do have that book. Would i need another book after this, about specific c++ to understand the language, used for games. I thought i was ready, so i started windows programming, but seems my c++ knowledge lack behind.

Share this post


Link to post
Share on other sites
it's actually the same as writing:

(*GameEngine::GetEngine()).GetSleep()

Maybe that will make it easier for you to understand. But as some people already wrote it's just a dereference. So it should be pretty basic.

You should check out C++ primer by lippman.

Share this post


Link to post
Share on other sites
Quote:
Original post by MadsGustaf
i do have that book. Would i need another book after this, about specific c++ to understand the language, used for games. I thought i was ready, so i started windows programming, but seems my c++ knowledge lack behind.


I just gave another look to the book, and while its structure makes it a great book, it doesn't discuss the C++ syntax much, so maybe you'll have to read another book (or intarweb resource, for example this one).

Share this post


Link to post
Share on other sites
so reading that tutorial, and accelerated c++ will give me the information i need? :) my problem is i use alot of time thinking about the "next step" and when ill be ready to open my "begginning game programming" book. I actiuly use more time thinking and surfing for this answer than reading the book. So if i can get a clear answer by someone, it would save my day! :D

Share this post


Link to post
Share on other sites
Are you reading that Win32 programming book of Michael Morrison? I recognise the way you access the game engine class through a static member function. I read it about two years ago and I must say it's a very good preparation for something more advanced such as OpenGL or Direct3D programming. Although it isn't very detailed, it's also useful for brushing up on your Windows programming skills. I do think though, that you should have a working knowledge of C++ before attempting to accomplish anything with it. If you weren't sure about the "->" operator, I don't think you went very far with C++ yet. Anyway, I for one thing had a lot of fun implementing the various 2D games like a customized version of Frogger. But the best thing about the book is that you can customize the 2D-engine you built even further. I extended it with all kinds of need scrolling techniques etc...

It's a small world...
Jeroen

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this