copy constructor

Hi all,

I have a class A consisting of a member data which is a pointer B* that points to some abstract class B. Now when I try to write the copy constructor of the class A, I don't know how to handle the copying of the data B*. I cannot use "new" as it is abstract. Does that mean I have to write some virtual constructor for class B?

Please help,

Thanks in advance
Why can't use you new?
1
2
3
4
5
6
7
8
9
10
class B { /* ... */ };

class A
{
private: 
  B* m_b;
public:
  A (A& obj) : m_b (new B ( obj.m_b ) ) {  }
  ~A() { delete m_b; }
};
Last edited on
Answer to clearly rhetorical question removed.
Last edited on
Yes, I did miss the abstract part. That was pretty interesting to read.
Topic archived. No new replies allowed.