Advertisement
TwITe

Untitled

Dec 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. protected:
  6.     int i;
  7. public:
  8.     A(int a) {
  9.         i = a;
  10.         cout  << "A's constructor called" << endl;
  11.     };
  12. };
  13.  
  14. class B: A {
  15. private:
  16.     A a_object;
  17. public:
  18.     B(int a):A(a), a_object(a) {
  19.         cout << "B's constructor called";
  20.     };
  21.  
  22.     int get_value() {
  23.         return a_object.i;
  24.     }
  25. };
  26.  
  27. int main() {
  28.     B object(10);
  29.     cout << endl;
  30.     //cout << object.get_value();
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement