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

后端 未结 3 1229
余生分开走
余生分开走 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:54

    Your code looks fine to me. And ideone agrees: see this link. But that's with gcc-4.3.4. However, my gcc-4.4.0 doesn't accept it. So whatever the reason, it's not obvious.

    Edited to add: The following variant compiles under gcc-4.4.0:

    int localStatus = 42 ? GOOD : BAD;
    

    Reminder: the following code doesn't compile:

    int localStatus = (num == 42) ? GOOD : BAD;
    

    So somebody has screwed up somewhere.

提交回复
热议问题