Static function returning object reference

  • Thread starter Christian Schilling
  • Start date
C

Christian Schilling

Hi,

I am wondering whether a static function can return a reference to an
instance that was created?
Say I have an instance of an object "foo" created somewhere.
Some other part of the program wants to access that object, but does not
know where it is .I want to circumvent the global variable thing, if
possible.
so sth like:
include "foo.h"
...
foo = *myfoo;
foo = foo::getInstance();
...

would be great if it works ...

Response will be greatly appreciated. Preferably binary answers ; )
 
T

Thomas Tutone

Christian said:
I am wondering whether a static function can return a reference to an
instance that was created?

Yes, it can.
Say I have an instance of an object "foo" created somewhere.
Some other part of the program wants to access that object, but does not
know where it is .I want to circumvent the global variable thing, if
possible.
so sth like:
include "foo.h"
..
foo = *myfoo;
foo = foo::getInstance();

The above lines make no sense.
would be great if it works ...

Response will be greatly appreciated. Preferably binary answers ; )

Look up "static initialization fiasco" in the FAQ for examples of what
you're looking for:

http://www.parashift.com/c++-faq-lite

Best regards,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top