How to initialize a static const member in C++?

后端 未结 4 1639
陌清茗
陌清茗 2020-11-29 00:08

Is it possible to initialize a static const value outside of the constructor? Can it be initialized at the same place where member declarations are found?

cl         


        
4条回答
  •  一个人的身影
    2020-11-29 00:56

    Just for the sake of completeness, I am adding about the static template member variables.

    template struct X{
       static T x;
    };
    
    template T X::x = T();
    
    int main(){
       X x;
    }
    

提交回复
热议问题