?
=?ISO-8859-1?Q?Szabolcs_Horv=E1t?=
This is a newbie question. Suppose I have a class A (see the attached
code) which contains a pointer that can point to an object of either
type D1 or D2. How do I write a copy constructor for A, so that the
object that it references also gets copied (I don't know whether it is a
D1 or D2 object)?
Thank you for your answers in advance,
Szabolcs
----
class B {
public:
virtual void print() = 0;
};
class D1 : public B {
int i;
public:
void print() { cout << i; }
};
class D2 : public B {
double x;
public:
void print() { cout << x; }
};
class A {
B *b;
};
code) which contains a pointer that can point to an object of either
type D1 or D2. How do I write a copy constructor for A, so that the
object that it references also gets copied (I don't know whether it is a
D1 or D2 object)?
Thank you for your answers in advance,
Szabolcs
----
class B {
public:
virtual void print() = 0;
};
class D1 : public B {
int i;
public:
void print() { cout << i; }
};
class D2 : public B {
double x;
public:
void print() { cout << x; }
};
class A {
B *b;
};