Advertisement
TwITe

Untitled

Jan 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6.     A() {
  7.         cout << "Class A Object created" << endl;
  8.     }
  9. };
  10.  
  11.  
  12. class B {
  13. private:
  14.     A a;
  15. public:
  16.     B(A arg): a(arg) {
  17.         cout << "Class B Object created" << endl;
  18.     }
  19. };
  20.  
  21. class C {
  22. private:
  23.     A a;
  24. public:
  25.     C(A& arg): a(arg) {
  26.         cout << "Class C Object created" << endl;
  27.     }
  28. };
  29.  
  30. class D {
  31. private:
  32.     A& a;
  33. public:
  34.     D(A& arg): a(arg) {
  35.         cout << "Class D object created" << endl;
  36.     }
  37. };
  38.  
  39. void test() {
  40.     A a;
  41.     cout << "----------" <<  endl;
  42.     B b(a);
  43.     cout << "----------" <<  endl;
  44.     C c(a);
  45.     cout << "----------" <<  endl;
  46.     D d(a);
  47.     cout << "----------" <<  endl;
  48. }
  49.  
  50. int main() {
  51.     test();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement