|
-
December 14th, 2007, 06:12 AM
#1
Copy cons for integer pointer
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
-
December 14th, 2007, 06:30 AM
#2
Re: Copy cons for integer pointer
Please use code tags when posting code.
Code:
test(const test& obj)
{
i = new int(*obj.i);
}
You will also need a destructor and an implementation of the assignment operator.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Please read Information on posting before posting, especially the info on using [code] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|