Vorrei sapere perché il seguente codice non viene compilato:C++ di errore: funzione base è protetto
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++
uscita:
~/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
Questo codice è stato adattato da here e non vedo uno che si lamenta al forum di discussione. Inoltre, sto usando g ++ 4.7.2 e lo stesso codice compila e collega bene con egcs-2.91.66.
O un compilatore è bacato, o l'altro è. : D – Wug