Answer to Question #247517 in C++ for Elena

Question #247517
Write a program using copy constructor to copy data of an object to another
object.
1
Expert's answer
2021-10-06T16:34:04-0400
#include<iostream>




using namespace std;


class Copy {
  
   int a, b;
public:


   


   Copy(int x, int y) {
     
      a = x;
      b = y;
      cout << "\nParameterized Constructor called\n";
   }


   


   Copy(const Copy& obj) {
      
      a = obj.a;
      b = obj.b;
      cout << "Copy Constructor called\n";
   }


   void output() {
      cout << "\nNumbers :" << a << "\t" << b;
   }
};


int main() {
   
   Copy obj(10, 20);


   
   Copy obj2(obj);


   
   Copy obj3 = obj;


   obj.output();
   obj2.output();
  obj3.output();
   
   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS