473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Static function returning object reference


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 ; )

--
"Experience is what you get when you did not get what you wanted" author
unknown
"A bug in the code is worth two in the documentation" author unknown

Mar 22 '06 #1
2 2315
Christian Schilling wrote:
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

Mar 22 '06 #2

"Thomas Tutone" <Th***********@yahoo.com> wrote:
The above lines make no sense. ermh ... true ... I try to use a brain next time ...
Look up "static initialization fiasco" in the FAQ for examples of what
you're looking for:

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

Yups, worked for me.
Thanks, Thomas!

Regards,
Christian
--
"Experience is what you get when you did not get what you wanted" author
unknown
"A bug in the code is worth two in the documentation" author unknown

Mar 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Yu | last post by:
I have found that the static object is initialised at the time when the shared libary is loaded. The initialisation caused the invocation of the constructor. May I know of any way that I can...
7
by: BrianJones | last post by:
Hi, if you have a function, how is it possible to return an array? E.g.: unsigned long function(...) // what I want to do, obviously illegal I do know such would be possible by using a dynamic...
14
by: Mike Labosh | last post by:
How do you define whether the return value of a function is ByRef or ByVal? I have a utility class that cleans imported records by doing *really heavy* string manipulation in lots of different...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
6
by: Jia | last post by:
Hi all, I have a class foo which has a static vector of pointers of type base class, and a static function to set this vector. #include <iostream> #include <vector> using namespace std;...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
8
by: aarklon | last post by:
Hi all, see:- http://linuxgazette.net/issue51/pramode.html
5
by: DamienS | last post by:
Hi, I have a static method in a class and I need to be able to return a reference to "this". Googling around, I found a heap of discussions of the pros/cons of "abstract static" etc. It was...
2
by: chenxinleo | last post by:
Hi, When i use some standard library functions and fields,which return char* type(like ctime in time.h, optarg in getopt.h)and do not have to be freed after calling,i always worry about memory...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.