Advertisement
Guest User

Untitled

a guest
Apr 9th, 2021
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #include <stdio.h>
  4.  
  5. class A {
  6. public:
  7.  
  8.     A() { _objName = "no name"; };
  9.  
  10.     A(string objName) {
  11.         _objName = objName;
  12.         printf("Constructor %s\n", _objName.c_str());
  13.     };
  14.  
  15.     ~A() {
  16.         printf("Destructor %s\n",_objName.c_str());
  17.     };
  18.  
  19.     A(const A& obj) {
  20.         printf("Deep copy when initial.\n");
  21.     }
  22.  
  23.     A(const A&& obj) {
  24.         printf("Shadow copy when initial.\n");
  25.     }
  26.  
  27.     A copy(void){
  28.         return *this;
  29.     }
  30.  
  31.     string _objName = "default";
  32. };
  33.  
  34. A copy(string objName)
  35. {
  36.     A b(objName);
  37.     return b;
  38. }
  39.  
  40. int main() {
  41.  
  42.  
  43.     A a("a");
  44.     a.copy();
  45.     printf("\n------------------------------------\n\n");
  46.  
  47.     A c(copy("b"));
  48.  
  49.     printf("\n------------------------------------\n\n");
  50.  
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement