#include <iostream> using namespace std; class student { private: int x, y; public: student(int x1, int y1) { x=x1; y=y1; } student(student &s3) { x = s3.x; y = s3.y; } void display() { cout << "s2.x = " << x << ", s2.y = " << y; cout << "\ns3.x = " << x << ", s3.y = " << y; } }; int main() { student s2(12, 45); // Parameterized constructor student s3 = s2; // Copy constructor s3.display();//Display the values assigned by constructors return 0; }
2 Comments
The first constructor is not normal bro. Its parameterized constructor because it contains arguments
ReplyDeleteYes we will be editing it... Sorry for the typing error
Delete