Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Constructor.cpp
#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; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
BridgeEdge
Anagrams WIP
Trapping rain water problem
NBiggestNum
GCC bug #79511
IAR compiler bug test code
strcpy
Hi
Dar
passing by reference vs passing by value
Please log in to post a comment.