singleton problem

M

Magcialking

I'm writting a code using singleton idea much like this one:

//I have it simplified as to be brief
class a{
public:
static a&get(){return obj;}

void fun(){}

private:
static a obj;
}

int main(){
a::get().fun();
}

the problem occurs during the linking process I guess, 'cause the
message returned as follow

main.cpp:: undefined reference to `filelist::_obj'

without line number

I don't know what's going wrong here

Could anybody help me?
 
D

Default User

Magcialking said:
I'm writting a code using singleton idea much like this one:

//I have it simplified as to be brief
class a{
public:
static a&get(){return obj;}

void fun(){}

private:
static a obj;
}

int main(){
a::get().fun();
}

the problem occurs during the linking process I guess, 'cause the
message returned as follow

main.cpp:: undefined reference to `filelist::_obj'

<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.11>




Brian
 
V

visu.murthy

Hi,

I presume you had forgotten to end the definition of the class witha
semi clon (;)

Viswanath
 
B

bankrock

you should write the definition of the static variable after the class
decleration, like this:

a a::eek:bj;

otherwise there would be a link problem.
"Magcialking дµÀ£º
"
 
D

Default User

Hi,

I presume you had forgotten to end the definition of the class witha
semi clon (;)

Who are you talking to? You replied to my message, but I didn't write
that code.

You also completely ignored this part that i DID write:




Brian
 
B

BobR

(e-mail address removed) wrote in message ...

Huh? Let's put this in the proper order.
On Dec 12, 9:27 am, "Default User" wrote:
text -- Show quoted text -
Hi,

I presume you had forgotten to end the definition of the class witha
semi clon (;)
Viswanath

What class definition?
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top