How to declare a static const char* in your header file?

后端 未结 9 1083
盖世英雄少女心
盖世英雄少女心 2021-01-31 13:26

I\'d like to define a constant char* in my header file for my .cpp file to use. So I\'ve tried this:

private:
    static const char *SOMETHING = \"sommething\";         


        
9条回答
  •  星月不相逢
    2021-01-31 14:17

    class A{
    public:
       static const char* SOMETHING() { return "something"; }
    };
    

    I do it all the time - especially for expensive const default parameters.

    class A{
       static
       const expensive_to_construct&
       default_expensive_to_construct(){
          static const expensive_to_construct xp2c(whatever is needed);
          return xp2c;
       }
    };
    

提交回复
热议问题