5

I have some code that is doing the following but I don't understand what the using BaseTypeX::BaseTypeX is actually doing in this code. The rest of it I understand so please don't explain template specialization etc.

template<typename TReturn, typename... TArgs>
class ClassX<TReturn(TArgs...)> : public Internal::ClassXImpl<TReturn, TArgs...> {
public:

    using BaseTypeX = Internal::ClassXImpl<TReturn, TArgs...>;
    using BaseTypeX::BaseTypeX; // what is this doing exactly?

    inline ClassX() noexcept = default;

    // member function
    template<class TThis, class TFunc>
        inline ClassX(TThis* aThis, TFunc aFunc) {
            this->bind(aThis, aFunc);  // note bind is implemented in the ClassXImpl class
        }   
bjackfly
  • 3,236
  • 2
  • 25
  • 38

2 Answers2

10

It means you inherit all the constructors of Internal::ClassXImpl<TReturn, TArgs...>. A simpler example might illustrate this better:

struct Foo
{
  Foo(int);
  Foo(int, double);
  Foo(std::string);
};

struct Bar : Foo
{
  using Foo::Foo;
};

int main()
{
  Bar b1(42); // OK, Foo's constructors have been "inherited"
  Bar b2(42, 3.14); // OK too
  Bar b2("hello");  // OK
}

Without the using Foo::Foo, you would have to declare and define all the constructors in Bar, and call the respective Foo constructor in each one of them.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • 1
    +1 oh wow I did not know that! Thanks so much. I will accept this as an answer once the time passes to allow me to – bjackfly Apr 09 '14 at 20:22
1

It means template class ClassX inherits its base's constructors. See here for a discussion on the topic.

Community
  • 1
  • 1