Google News
logo
CPP - Interview Questions
What is a copy constructor in c++
A Copy constructor is an overloaded constructor used to declare and initialize an object from another object.
 
Copy Constructor is of two types :

Default Copy constructor : The compiler defines the default copy constructor. If the user defines no copy constructor, compiler supplies its constructor.
User Defined constructor : The programmer defines the user-defined constructor.
 
Syntax Of User-defined Copy Constructor :
 
Class_name(const class_name &old_object);  

Consider the following situation :
class A  
{  
    A(A &x) //  copy constructor.  
   {  
       // copyconstructor.  
   }  
}
   
Advertisement