bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_2 / eduincs / pgrm_017.cpp

pgrm_017.cpp (414B)


      1 /* Copy Constructor */
      2 
      3 #include<iostream>
      4 using namespace std;
      5 class A {
      6 private: 
      7 	int x;
      8 	double y;
      9 public:
     10 	A(int a, double b) {
     11 		x = a; y = b;
     12 	}
     13 	A(A & ob) {
     14 		// Copy constructor
     15 		x = ob.x;
     16 		y = ob.y;
     17 	}
     18 	void display() {
     19 		cout << "x = " << x << " y = " << y << endl;
     20 	}
     21 };
     22 
     23 int main() {
     24 	A obj(20, 23.5);
     25 	cout << "obj: ";
     26 	obj.display();
     27 	A obj2(obj);
     28 	cout << "obj2: ";
     29 	obj2.display();
     30 	return 0;
     31 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror