I recently learned this about using static variables in C++ classes. You need to define the static data member outside the class declaration. Failure to do this results in a linker error, the reason being because without the definition the compiler doesn't know which translation unit (hence object file) the member is supposed to go.
Sample code:
foo.hOne more reason why I don't consider myself a C++ programmer.
class bar {
public:
int getBar1();
private:
static int bar1;
};
foo.cpp
#include "foo.h"
int bar::bar1;
.....
....
No comments:
Post a Comment