Possible Duplicate:
What does it mean to have an undefined reference to a static member?
I have a static class as follows:
.h file
class c1 {
public:
static int disconnect();
private:
static bool isConnected;
};
.cpp file
#include c1.h
int c1::disconnect()
{
c1::isConnected = false;
return 0;
}
However when I compile, there is an error
undefined reference to `c1::m_isConnected'
Please help!
You have to provide an actual object instance for the static class members. Add the following to your .cpp file:
To initialize it to a specific value, add an initializer:
(By the way, classes in C++ cannot be static. Classes are just types. Only class members can be static.)