Monday, April 5, 2021

copy constructor (OOP) (17)

                             /*copy constructure

                            *******************/


#include<iostream>

using namespace std;

class test 

{

private:  //this is the private part of the class

int code,price;

public: //this is the public part of the class

test(int s,int u) //this is a parameterized constructure

{

          code=s;  

          price=u;

}

test(const test &t) //this is copy constructure

{

code=t.code;

price=t.price;

}

void display() //this function display the code and price

{

cout<<"the code is:"<<code<<endl;

cout<<"the price is:"<<price<<endl;

}

};

int main()

{

test t(101,3000); //here we creat an object and pass an arguments

test t1(t); //here we creat the second object and pass the object as an arrguments

test t2(t1);

cout<<"first"<<endl;

t.display();

cout<<"second"<<endl;

t1.display();

cout<<"third"<<endl;

t2.display();

}

No comments:

Post a Comment