Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Foo {
  6.     private:
  7.         int a = 0;
  8.        
  9.     public:
  10.         void doA() {
  11.             a += 1;
  12.             cout << "a=" << a << endl;
  13.         }
  14.        
  15.         virtual void doB() = 0;
  16.        
  17. };
  18.  
  19. class Bar: private Foo {
  20.     public:
  21.     static Foo *createFoo() {
  22.         return new Bar();
  23.     }
  24.    
  25.     void doB() {
  26.         doA();
  27.     }
  28.    
  29. };
  30.  
  31. int main()
  32. {
  33.     Foo *f = Bar::createFoo();
  34.     f->doA();
  35.     f->doB();
  36.     delete f;
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement