Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone please explain the using BaseTypeX::BaseTypeX in this code?

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
        }   
like image 721
bjackfly Avatar asked Apr 09 '14 20:04

bjackfly


People also ask

What is the base type?

The base type is the type from which the current type directly inherits. Object is the only type that does not have a base type, therefore null is returned as the base type of Object.

What is base type class in C#?

A base class, in the context of C#, is a class that is used to create, or derive, other classes. Classes derived from a base class are called child classes, subclasses or derived classes. A base class does not inherit from any other class and is considered parent of a derived class.

Is Typeof C#?

The typeof is an operator keyword which is used to get a type at the compile-time. Or in other words, this operator is used to get the System. Type object for a type.


1 Answers

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.

like image 77
juanchopanza Avatar answered Sep 30 '22 04:09

juanchopanza