Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

C++ Copy Constructor

// Example: Implicit copy constructor
  
#include<iostream>
using namespace std;
  
class Sample
{          
      int id;
    public:
    void init(int x)
    {
        id=x;    
    }    
    void display()
    {
        cout<<endl<<"ID="<<id;
    }
};
  
int main()
{
    Sample obj1;
    obj1.init(10);
    obj1.display();
      
    Sample obj2(obj1); //or obj2=obj1; 
    obj2.display();
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Copy #Constructor
ADD COMMENT
Topic
Name
7+9 =