Why don't static member variables play well with the ternary operator?

后端 未结 3 1212
余生分开走
余生分开走 2020-12-31 05:07

Here\'s the deal. I have a static class which contains several static functions used for getting input. The class contains a private static member variable for indicating wh

3条回答
  •  囚心锁ツ
    2020-12-31 05:47

    class Test {
        static const int GOOD = 0;
        static const int BAD = 1;
    };
    

    These are only declarations; they are not definitions. You need to provide definitions of the static member variables, outside of the definition of the class, in one of your .cpp files:

    const int Test::GOOD;
    const int Test::BAD;
    

    Alternatively, for integer constants, it is often more convenient to use an enum:

    class Test {
        enum { 
            GOOD = 0,
            BAD = 1 
        };
    };
    

提交回复
热议问题