Static const string won't get initialized

后端 未结 6 1685
一生所求
一生所求 2021-01-13 21:00

I have some static const strings as private members of my C++ class. I am aware of the declaration in .h and definition (and initialization) in .cpp practice. In the class c

6条回答
  •  庸人自扰
    2021-01-13 21:25

    Are you defining it as such?

    class X
    {
    public:
          static string i;
    };
    string X::i = "blah"; // definition outside class declaration
    

    See: Static data members (C++ only)

提交回复
热议问题