I am trying to convert from a base class to a derived class.
I have the following constructor, however, the compiler complains with:
no matching function for call to ‘baseObject::baseObject()’
constructor:
derivedObject(const baseObject &base, const std::string &extra1)
{
baseparameter1 = base.baseparameter1;
baseparameter2 = base.baseparameter2;
extraparameter1 = extra1;
}
Any advice?
Every constructor begins by initializing all base classes and direct members, before you get to the
{. Instead of using assignments in the body, use a member initializer list:This is better style and also avoids problems like the one you ran into.