C++ where to initialize static const

前端 未结 5 1177
走了就别回头了
走了就别回头了 2020-11-27 11:17

I have a class

class foo {
public:
   foo();
   foo( int );
private:
   static const string s;
};

Where is the best place to initialize the

5条回答
  •  一向
    一向 (楼主)
    2020-11-27 11:27

    Static members need to be initialized in a .cpp translation unit at file scope or in the appropriate namespace:

    const string foo::s( "my foo");
    

提交回复
热议问题