Inheriting Constructors
In another move to simplify coding, C++11 provides a mechanism for derived classes to inherit constructors from the base class. C++98 already had a syntax for making functions from a namespace available:
namespace Box{ int fn(int) { ... } int fn(double) { ... } int fn(const char *) { ... }}using Box::fn;
This makes all the overloaded fn functions available. The same technique works for making nonspecial member functions of a base class available to a derived class. For example, consider the following code:
class C1{...public:... int fn(int j) { ... } double fn(double w) { ... } void fn(const char * s) { ... }};class C2 : public C1{...public:... using C1::fn; double fn(double) { ... };};...C2 c2; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access