I want to test a simple singleton case, write a class C below:
class C {
static C * ptr_c;
C(){}
public:
static C* getInstance()
{
if (ptr_c == nullptr)
ptr_c = new C();
return ptr_c;
}
void show()
{
std::cout << "this is class C" << std::endl;
}
};
with test code:
int main()
{
C* ptrc = C::getInstance();
ptrc->show();
}
but it ouput link error:
Undefined symbols for architecture arm64: "C::ptr_c", referenced from: C::getInstance() in test-1db68d.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)