Generation

class from descriptionTue, 10 Jan 2023

Write a c++ programs to demonstrate copy constructor

#include <bits/stdc++.h> using namespace std; class Point { int x, y; public: Point(int x1, int y1) { x = x1; y = y1; } int getX() { return x; } int getY() { return y; } }; int main() { Point p1(10, 15); Point p2 = p1; cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY(); cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY(); return 0; }

Questions about programming?Chat with your personal AI assistant