C++: warning: '…' declared with greater visibility than the type of its field '…::'

前端 未结 3 1187
礼貌的吻别
礼貌的吻别 2021-01-17 23:48

I\'m getting these two warnings (with GCC 4.2 on MacOSX):

/Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openliero

3条回答
  •  攒了一身酷
    2021-01-18 00:13

    It's because you forgot to declare the inheritance as public.

        struct MainLockDetector : public Action {
             bool wait(Uint32 time) { /* ... */ }
             int handle() { /* ... */ }
        };
    

    This causes the "Action" members to be private. But, you've just overridden an Action private member as public (public default in a struct), which could break encapsulation, hence the warning.

提交回复
热议问题