Advertisement
framp

Copy constructor test

Mar 29th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Test01 {
  6.     public:
  7.         int value;
  8.         Test01(int v=0): value(v) { cout << "Test01 " << value << " Constructor;\n"; }
  9.         Test01(const Test01 &T): value(T.value) { cout << "Test01 " << value << " Copy Constructor;\n"; }
  10.         ~Test01(){ cout << "Test01 " << value << " Destructor;\n"; }
  11.         Test01 & operator= (const Test01 &T){ cout << "Test01 " << value << "  Assignment Operator;\n"; value = T.value; return *this; }
  12. };
  13.  
  14. class Test02 : public Test01 {
  15.     public:
  16.         Test02(int v=0): Test01(v){ cout << "Test02 " << value << " Constructor;\n"; }
  17.         //Test02(const Test02 &T){ cout << "Test02 " << value << " Copy Constructor;\n"; }
  18.         ~Test02(){ cout << "Test02 " << value << " Destructor;\n"; }
  19. };
  20.  
  21. int main(){
  22.     Test02 a(3);
  23.     cout << "a: " << a.value << "\n";
  24.     Test02 b = a;
  25.     cout << "b: " << b.value << "\n";
  26.    
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement