Hi All
class test
{
int *i;
public:
test(int n)
{
i = new int(n)
}
test(const test& obj)
{
}
void disp()
{
cout<<*i<<endl;
}
};
Please tell me how to write copy constructor for this class
Thanks
Printable View
Hi All
class test
{
int *i;
public:
test(int n)
{
i = new int(n)
}
test(const test& obj)
{
}
void disp()
{
cout<<*i<<endl;
}
};
Please tell me how to write copy constructor for this class
Thanks
Please use code tags when posting code.You will also need a destructor and an implementation of the assignment operator.Code:test(const test& obj)
{
i = new int(*obj.i);
}