- Example
In this lesson, we'll look at the example of constructor inheriting with the help of the keyword `using`.
We'll cover the following...
Example: Constructor inheriting #
Press + to interact
#include <iostream>#include <string>class Base{public:Base() = default;Base(int i){std::cout << "Base::Base("<< i << ")" << std::endl;}Base(std::string s){std::cout << "Base::Base("<< s << ")" << std::endl;}};class Derived: public Base{public:using Base::Base;Derived(double d){std::cout << "Derived::Derived("<< d << ")" << std::endl;}};int main(){// inheriting BaseDerived(2011); // Base::Base(2011)// inheriting Base // Base::Base(C++0x)Derived("C++0x");// using DerivedDerived(0.33); // Derived::Derived(0.33)}
...