Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo{
- };
- class Bar : Foo{
- public:
- Foo* asFoo(){
- return (Foo*)(this);
- }
- };
- int main(){
- //Foo x = Bar();
- // error: ‘Foo’ is an inaccessible base of ‘Bar’
- //Foo y = (Foo)Bar();
- // error: ‘Foo’ is an inaccessible base of ‘Bar’
- Foo z = *(Bar().asFoo());
- // OK
- }
Add Comment
Please, Sign In to add comment