C++ Static variable and unresolved externals error

后端 未结 2 966
隐瞒了意图╮
隐瞒了意图╮ 2020-12-12 06:34

I was hoping I could get some clarification on static variables of a class.

For example: I have two different classes which perform completely different functions,

相关标签:
2条回答
  • 2020-12-12 07:09

    static variables inside a class must still be defined somewhere, just like methods:

    Put this in main.cpp:

    beta alpha::var;
    
    0 讨论(0)
  • 2020-12-12 07:10

    Add this to main.cpp:

    beta  alpha::var;
    

    var in h-file is only type declaration. Variable should be created in some source file.

    0 讨论(0)
提交回复
热议问题