|
-
December 5th, 2011, 06:59 PM
#1
Need help with simple copy constructor
I'm a little confused about copy constructors and could use some help. Here's my situation: I have two classes, A and B. Class B is a child of class A. Class A looks something like this:
Code:
class A
{
public:
A::A(); // constructor
// some other functions
private:
char* name; // the name of the object is stored in a character array
};
Class B just has some more functions and more data. My question is how do I properly implement a copy constructor, since class A has it's name stored in the heap? I know a copy constructor is needed, but I'm not quite sure how to do it. If I create a copy constructor and inside it dynamically allocate memory and copy the name over for the new object, do I also have to copy all of the data members over?
Thanks for your advice
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
|