fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Base
  5. {
  6. void foo() const {
  7. cout << "Base::foo()\n";
  8. }
  9. };
  10.  
  11. struct Derived : private Base
  12. {
  13. const Base* get() const {
  14. return this;
  15. }
  16. };
  17.  
  18. int main()
  19. {
  20. Derived d;
  21. //const Base *b = &d; //uncomment to get error
  22. const Base *b = d.get();
  23. b->foo();
  24. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
Base::foo()