Advertisement
pulchroxloom

main.cpp

Jan 29th, 2021
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include "A.h"
  3.  
  4. using namespace std; // Avoid extra typing, but is generally bad
  5.  
  6. int main() {
  7.     A obj1; // Default Constructor
  8.     cout << "obj1: " << obj1 << endl;
  9.     A* ptr_obj1; // Doesn't call anything
  10.     cout << "ptr_obj1: " << "nullptr" << endl;
  11.     A obj2(obj1); // Copy Construction (could use {} instead)
  12.     cout << "obj2: " << obj2 << endl;
  13.     obj1 = obj2; // Copy Assignment
  14.     cout << "obj1: " << obj1 << endl << "obj2: " << obj2 << endl;
  15.     A obj3(std::move(obj2)); // Move Construction
  16.     cout << "obj2: " << "NULL" << endl << "obj3: " << obj3 << endl;
  17.     obj1 = std::move(obj3); // Move Assignment
  18.     cout << "obj1: " << obj1 << endl << "obj3: " << "NULL" << endl;
  19.     ptr_obj1 = new A(); // Default Constructor
  20.     cout << "ptr_obj1: " << *ptr_obj1 << endl;
  21.     delete ptr_obj1;
  22.     return 0;
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement