D
daniel
Hello ,
I have the following code , which implements the singleton pattern:
class Singleton{
private:
static Singleton* uniqueInstance;
//other useful instance variables here
Singleton(){
cout<<"Object created!"<<endl;
}
public:
static Singleton* getInstance(){
if(uniqueInstance == NULL)
uniqueInstance = new Singleton();
return uniqueInstance;
}
};
int main(){
Singleton::getInstance();
return 0;
}
But when i try to compile it , i get the following error:
dan@sea:~/school/dp$ g++ -o singleton singleton.cpp
/tmp/ccHL1rvi.o: In function `Singleton::getInstance()':
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x8):
undefined reference to `Singleton::uniqueInstance'
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x2e):
undefined reference to `Singleton::uniqueInstance'
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x54):
undefined reference to `Singleton::uniqueInstance'
collect2: ld returned 1 exit status
Can you enlighten me
Thanks,
Daniel.
I have the following code , which implements the singleton pattern:
class Singleton{
private:
static Singleton* uniqueInstance;
//other useful instance variables here
Singleton(){
cout<<"Object created!"<<endl;
}
public:
static Singleton* getInstance(){
if(uniqueInstance == NULL)
uniqueInstance = new Singleton();
return uniqueInstance;
}
};
int main(){
Singleton::getInstance();
return 0;
}
But when i try to compile it , i get the following error:
dan@sea:~/school/dp$ g++ -o singleton singleton.cpp
/tmp/ccHL1rvi.o: In function `Singleton::getInstance()':
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x8):
undefined reference to `Singleton::uniqueInstance'
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x2e):
undefined reference to `Singleton::uniqueInstance'
singleton.cpp:
(.text._ZN9Singleton11getInstanceEv[Singleton::getInstance()]+0x54):
undefined reference to `Singleton::uniqueInstance'
collect2: ld returned 1 exit status
Can you enlighten me
Thanks,
Daniel.