What is a copy constructor ? Give a suitable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it.
A copy constructor is an overloaded constructor in which an object of the same class is passed as a reference parameter.
class Point
{
int x;
public:
Point(){
x=0;
}
Point(Point & p) // Copy constructor
{
x = p.x;
}
};
void main()
{
Point p1;
Point p2(p1);//Copy constructor is called here
}