Click to See Complete Forum and Search --> : Copy cons for integer pointer


sudeephooli
December 14th, 2007, 05:12 AM
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

treuss
December 14th, 2007, 05:30 AM
Please use code tags when posting code.test(const test& obj)
{
i = new int(*obj.i);
}You will also need a destructor and an implementation of the assignment operator.