Click here to Skip to main content
12,759,875 members (31,445 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++
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.

Posted 6-Dec-12 1:06am
Updated 6-Dec-12 1:17am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100