Public Group

what does the '-' operator do?

This topic is 4125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 on other sites
Quote:
 Original post by MadsGustafas 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 on other sites
-> dereferences a pointer when working with objects.

GetEngine() must be returning a pointer to an object, and the -> operator is dereferencing it so that it can call the GetSleep() method of that object.

http://www.fredosaurus.com/notes-cpp/structs/arrow.html This may explain it a little better than I.

Share on other sites
Quote:
Original post by Emmanuel Deloget
Quote:
 Original post by MadsGustafas 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 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 on other sites
Quote:
 Original post by MadsGustafi 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 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 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

• 11
• 20
• 12
• 9
• 34
• Forum Statistics

• Total Topics
631399
• Total Posts
2999847
×