Weird linker problem with static const class members
Please tell me, why gcc linker gives me the following error: "test_class::test_struct::constVar", referenced from: __ZN12lu_test_class27test_struct6constVar$non_lazy_ptr in test_class.o ?
My code (test_class.h):
class test_class
{
struct test_struct
{
static const int constV开发者_JAVA技巧ar = 0;
};
};
All references to constVar are in test_class scope in a usual static member access form: test_struct::constVar.
Provide the definition of the static member outside the class
const int test_class::test_struct::constVar;
This works for me.
精彩评论