Hello,
I am getting a linker error for a simple program to represent a singleton class.
Please find below the program which I have written:
#include <iostream>
using namespace std;
class Singleton
{
private:
Singleton(); // making constructor private
Singleton(const Singleton &); // making copy constructor const..prevent copy construction
Singleton& operator=(const Singleton &); // making overloaded assignment operator const..prevent assignment
static Singleton *ptr;
public:
static Singleton* get_instance()
{
if (ptr == NULL)
{
ptr = new Singleton;
}
return ptr;
}
};
Singleton *Singleton:tr=NULL;
int main()
{
cout << "hello :\n";
Singleton* pobj = Singleton::get_instance();
return 0;
}
I am getting the below error when I am compiling:
CC singleton.cpp
Undefined first referenced
symbol in file
Singleton::Singleton() singleton.o
ld: fatal: Symbol referencing errors. No output written to a.out
Please help me out of this problem.
Regards,
Harish