问题描述
我收到这两个警告(在MacOSX上使用GCC 4.2):
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/openlierox/build/Xcode/../../src/main.cpp:154:warning:'startMainLockDetector():: MainLockDetector'比它的字段类型更大的可见性'startMainLockDetector():: MainLockDetector :: '
/Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater visibility than the type of its field 'startMainLockDetector()::MainLockDetector::<anonymous>'
/ Users / az / Programmierung / openlierox / build / Xcode / ../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:warning:'startMainLockDetector():: MainLockDetector'声明的可见性比其基本Action'更大
/Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154:0 /Users/az/Programmierung/openlierox/build/Xcode/../../src/main.cpp:154: warning: 'startMainLockDetector()::MainLockDetector' declared with greater visibility than its base 'Action'
在此代码中:
struct Action {
virtual ~Action() {}
virtual int handle() = 0;
};
static void startMainLockDetector() {
/* ... */
struct MainLockDetector : Action {
bool wait(Uint32 time) { /* ... */ }
int handle() { /* ... */ }
};
/* ... */
}
不清楚这些警告是什么意思(什么可见性?)和如何解决它们。 (我真的希望类MainLockDetector为该函数的本地。)
I'm not exactly sure what these warnings mean (what visibility?) and how to fix them. (I really want the class MainLockDetector to be local for that function only.)
我已经编译了相同的代码与许多其他编译器(clang,GCC 3。
I have already compiled the same code with a lot of other compilers (clang, GCC 3.*, GCC 4.0, GCC 4.4, etc) and never got any warning for this code.
推荐答案
要解决这个问题,请尝试
To fix this problem, try one of below.
-
使用
#pragma GCC visibility push()
这样的语句。
#pragma GCC visibility push(hidden)
struct MainLockDetector : Action {
bool wait(Uint32 time) { /* ... */ }
int handle() { /* ... */ }
};
#pragma GCC visibility pop
使用 __ attribute__ (visibility(hidden)))
Use __attribute__ ((visibility("hidden")))
like this.
struct __attribute__ ((visibility("hidden"))) MainLockDetector : Action {
bool wait(Uint32 time) { /* ... */ }
int handle() { /* ... */ }
};
添加命令行选项-fvisibility = default。
Add the command line option -fvisibility=default.
有关详情,请参阅。
这篇关于C ++:warning:'...'声明的可见性比它的字段的类型更高... ...< anonymous>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!