i am trying to implement singleton on my io class i decleared two static members in the header file however the cpp does not know them.
class InputOutput{
//.h
private:
System* s;
static InputOutput* io;
static pthread_mutex_t lock;
}
//.cpp
InputOutput* InputOutput::getInstance(){
static bool initiallized = false;
if (pthread_mutex_init(&lock, NULL) != 0){
cout << "error in initiallize lock" << endl;
}
if(!initiallized){
pthread_mutex_lock(&lock);
if(!initiallized){
io = new InputOutput();
initiallized = true;
}
pthread_mutex_unlock(&lock);
}
return io;
}
the problem is:
undefined reference to InputOutput::lock'
undefined reference to
InputOutput::io'