Weird linker problem with static const class members

旧街凉风 提交于 2019-12-10 22:53:39

问题


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 constVar = 0;
    };
};

All references to constVar are in test_class scope in a usual static member access form: test_struct::constVar.


回答1:


Provide the definition of the static member outside the class

const int test_class::test_struct::constVar;

This works for me.



来源:https://stackoverflow.com/questions/6138895/weird-linker-problem-with-static-const-class-members

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!