Computer Science, asked by 1974pinkysingh, 5 months ago

write a program to print your name amd copy it into another object by using copy constructor​

Answers

Answered by suchi1126
0

Answer:

C++Copy Contructor

Explanation:

C++Copy Contructor

Answered by parthu2011
1

code:

#include<iostream>  

using namespace std;  

class Point  

{  

private:  

int x, y;  

public:  

Point(int x1, int y1) { x = x1; y = y1; }  

// Copy constructor  

Point(const Point &p2) {x = p2.x; y = p2.y; }  

int getX()   { return x; }  

int getY()   { return y; }  

};  

int main()  

{  

Point p1(10, 15); // Normal constructor is called here  

Point p2 = p1; // Copy constructor is called here  

// Let us access values assigned by constructors  

cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY();  

cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY();  

return 0;  

}

output:

p1.x = 10, p1.y = 15

p2.x = 10, p2.y = 15

if you are pleased with answer in turn

please subscribe my youtube chanel(Ramakrishna Nallangari youtube channel) for my effort

search for  

Ramakrishna Nallangari in search box

of youtube

Similar questions