Incomprehensible linker problem with static const class members

Please tell me why the gcc linker gives me the following error: "test_class :: test_struct :: constVar" referenced: __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 constVar = 0; }; }; 

All references to constVar are in the test_class area in the usual form for accessing the static member: test_struct :: constVar .

+3
source share
1 answer

Specify a definition of a static member outside the class

 const int test_class::test_struct::constVar; 

This works for me.

+3
source

Source: https://habr.com/ru/post/896354/


All Articles