I want to do the equivalent of the following to initialize the data member my_abc
(which I suspect won't work):
class ABC { // abstract base class
public:
virtual ~ABC {};
}
class SomeClass {
public:
SomeClass(ABC& abc); // argument will actually be instance of derived class
private:
ABC my_abc; // needs to be set from constructor argument
}
SomeClass::SomeClass(ABC& abc) : my_abc(abc)
{...} // copy construct `my_abc` from argument
I suspect this won't work when a derived class of ABC
is passed to the SomeClass
constructor because the copy constructor of the derived class won't be called to initialize the my_abc
member.
Am I correct? If so, what should I do?