C++: warning: '...' declared with greater visibility than the type of its field '...::<anonymous>'
- by Albert
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' 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' declared with greater visibility than its base 'Action'
In this code:
struct Action {
virtual ~Action() {}
virtual int handle() = 0;
};
static void startMainLockDetector() {
/* ... */
struct MainLockDetector : Action {
bool wait(Uint32 time) { /* ... */ }
int handle() { /* ... */ }
};
/* ... */
}
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.)
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.