struct B {}; struct Klass : protected B { void foo(void) { static_cast<B*>(this); // Fine }}; struct Derived : public Klass { void bar(void) { static_cast<B*>(this); // Fine }}; int main() { Klass k; static_cast<B*>(&k); // nope Derived d; static_cast<B*>(&d); // nope}
Standard input is empty
prog.cpp: In function ‘int main()’: prog.cpp:19:20: error: ‘B’ is an inaccessible base of ‘Klass’ static_cast<B*>(&k); // nope ^ prog.cpp:21:20: error: ‘B’ is an inaccessible base of ‘Derived’ static_cast<B*>(&d); // nope ^
Standard output is empty
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!