Monday, March 10, 2014

Simple Example Program Of Copy Constructor Overloading In C++

//Program For Simple Example Program Of Copy Constructor Overloading In C++
#include<iostream>
#include<conio.h>
using namespace std;
class Code        {
    // Variable Declaration
    int a,b;
    public:

    //Constructor with Argument
    Code(int x,int y)            {

    // Assign Values In Constructor
    a=x;
    b=y;
    cout<<"\nCopy Constructor";
    }

    void Display()    {
    cout<<"\nValues :"<<a<<"\t"<<b;
    }
};

int main()                {
        Code Object(10,20);

        //Copy Constructor
        Code Object2=Object;

        // Constructor invoked.

        Object.Display();
        Object2.Display();
        getch();
}

No comments:

Post a Comment