If all you want to do is build an instance of the derived class from one parameter that you pass to the constructor of the base class, you can do this:
C ++ 03 (I added an explicit and passed a const link):
class DerivedClass : public BaseClass { public: explicit DerivedClass (const std::string& b) : BaseClass(b) {} };
C ++ 11 (gets all base class constructors):
class DerivedClass : public BaseClass { public: using BaseClass::BaseClass; };
If you want to call different DerivedClass constructors and call the BaseClass constructor for some other value, you can also do this:
class DerivedClass : public BaseClass { public: explicit DerivedClass () : BaseClass("Hello, World!") {} };
source share