N
nozyrev
Hi,
I apologize in advance if this is a very dumb question. I've been
struggling with this problem for some time: I have an abstract base
class called Base and n derived classes D1, D2, ....Dn. I would like
to have a constructor for each derived class that takes any of the
other derived classes as an argument so that these statements are
valid:
D1 d1;
D2 d2;
D3 d3a(d1);
D3 d3b(d2);
What is the syntax that I have to use for those statements to compile.
I realize that, for any given derived class i, I can't use Di (const
Base& b) as the constructor. Do i need to use virtual constructors? If
so, how?
Thanks for your help
I apologize in advance if this is a very dumb question. I've been
struggling with this problem for some time: I have an abstract base
class called Base and n derived classes D1, D2, ....Dn. I would like
to have a constructor for each derived class that takes any of the
other derived classes as an argument so that these statements are
valid:
D1 d1;
D2 d2;
D3 d3a(d1);
D3 d3b(d2);
What is the syntax that I have to use for those statements to compile.
I realize that, for any given derived class i, I can't use Di (const
Base& b) as the constructor. Do i need to use virtual constructors? If
so, how?
Thanks for your help