を保護されて、私は次のコードはコンパイルされません理由を知りたい:C++エラー:基本機能は
class base {
protected:
typedef void (base::*function_type)() const;
void function_impl() const {} // error: ‘void base::function_impl() const’ is protected
};
class derived: public base {
public:
operator function_type() const {
return boolean_test() == true ? &base::function_impl : 0; // error: within this context
}
protected:
virtual bool boolean_test() const = 0;
virtual ~derived() {}
};
int main(int argc, char* argv[]) {
}
g++
出力:
~/protected_test$ g++ src/protected_test.cpp
src/protected_test.cpp: In member function ‘derived::operator base::function_type() const’:
src/protected_test.cpp:4:8: error: ‘void base::function_impl() const’ is protected
src/protected_test.cpp:10:44: error: within this context
このコードはhereから適応していないと私は何を見ました1つはディスカッションフォーラムでそれについて不平を言う。また、私はg ++ 4.7.2を使用しています。同じコードをコンパイルし、egcs-2.91.66とうまくリンクします。
いずれかのコンパイラがバグか、またはどちらか一方がバグです。 :D – Wug