Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody, I was just wondering what this line really meant:
if (!Engine::GetEngine() -> GetIsWaiting());

I don't understand the "->" where GetEngine() function is like "looking inside (member)" GetIsWaiting(), whereas GetIsWaiting() it is not a class or smiliar. GetIsWaiting IT IS NOT a member of GetEngine() !!!
What is this supposed to be interpeted like? Both the constructor and function (Clearly) belong to the "GetEngine" class.

Thanks.
Posted
Updated 6-Dec-12 0:17am
v5

1 solution

It's not "looking inside" GetEngine - what happens is a lot more simple:
GetEngine is a function which returns a value - that value is a pointer to a class instance (presumably a GetEngine class instance)
The -> "looks inside" the class instance and finds the GetIsWaiting method, then calls it.
 
Share this answer
 
Comments
unscathed18 6-Dec-12 6:37am    
Woudln't be easier just to get the "this" pointer from the instanced object? Bytheway, Why it has to be an static member? Otherwise, the compiler won't let me go.
OriginalGriff 6-Dec-12 6:50am    
You need a pointer to the instanced object in order to evaluate the "this" pointer - which is the pointer to the instanced object! :laugh:

It has to be static, because otherwise you would need an instance of a class in order to access the GetEngine function.
It looks like this is an implementation of what is called a Singleton Pattern - there is only ever one instance of the class, and it is always accessed via a method - you cannot create one by using "new". If you call Engine::GetEngine() several times, it will always give you the same instance - and that is the only way to get the Engine to do anything.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900