0

In the below code, what does using Base::Base; do exactly? I suspect it "copies" all constructors verbatim, since I get access to Derived(std::string) by doing it, but is that the only effect of the statement? I originally found the statement in https://stackoverflow.com/a/3120537/5377635 and are unsuccessful in locating its description in the cpp reference.

class Base {
    Base(std::string name);
};

class Derived : public Base {
    using Base::Base; // <<----------
};
Community
  • 1
  • 1
Sheph
  • 625
  • 1
  • 6
  • 19
  • 2
    Yes, this is called "inheriting constructors". It performs a certain amount of magic when default arguments are present on a base constructor. – Kerrek SB May 06 '16 at 08:57
  • 1
    Thank you! The term inheriting constructors was enough for me to find it at http://en.cppreference.com/w/cpp/language/using_declaration Please leave an answer for me to close. – Sheph May 06 '16 at 09:04
  • Hm, it doesn't quite feel enough for an answer. Maybe you can find a full explanation of Stack Overflow and we can mark this question as a duplicate? – Kerrek SB May 06 '16 at 09:07
  • 1
    Sure thing, I found http://stackoverflow.com/questions/9979194/what-is-constructor-inheritance but not enough rep to mark duplicates yet. – Sheph May 06 '16 at 09:15

0 Answers0