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

谁说我不能喝 提交于 2019-12-01 16:50:48

To fix this problem, try one of below.

  1. Use #pragma GCC visibility push() statement like this.

    #pragma GCC visibility push(hidden)
    struct MainLockDetector : Action {
         bool wait(Uint32 time) { /* ... */ }
         int handle() { /* ... */ }
    };
    #pragma GCC visibility pop
    
  2. Use __attribute__ ((visibility("hidden"))) like this.

    struct __attribute__ ((visibility("hidden"))) MainLockDetector : Action {
         bool wait(Uint32 time) { /* ... */ }
         int handle() { /* ... */ }
    };
    
  3. Add the command line option -fvisibility=default.

For more details, refer http://gcc.gnu.org/wiki/Visibility.

There seems to be a problem with shared libraries. I assume you are writing a shared library. Look at this explanation. Try to add the command line option -fvisibility-inlines-hidden. The problem seems to be, that gcc tries to export some symbols of MainLockDetector (visible to linking executables and libraries), whereas Action is not exported (invisible to linking executables and libraries). So the visibility of MainLockDetector really is higher than the visibility of Action.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!