Calling the base class constructor without specifying its class

class MyDerived: public Incredble<Difficult< And<Complicated, Long>>, And<Even, Longer>, BaseClass, Name>
{
public:
  MyDerived();
}


MyDerived::MyDerived
: ???(params)
{}

Is there a way to call the base constructor without writing its full name and without entering it?

The reason is to avoid duplication of code and the introduction of several positions for changes if the parameter in the parameters of the base class template is changed.

Level 2:

template <uint32 C>
class MyDerived: public Incredble<Difficult< And<Complicated, Long>>, And<Even, Longer>, BaseClass, Name>
{
public:
  MyDerived();
}

template <uint32 C>
MyDerived::MyDerived<C> 
: ???(C)
{
}
+4
source share
2 answers

You can use name-injection name . Incredible<...>::Incrediblerefers to itself, and since MyDerivedit is not a class template, an unskilled search will look in the area of ​​its base classes:

MyDerived::MyDerived
: Incredble(params)
{}

Incredible , . , injected-class-name (h/t Johannes Schaub-litb):

MyDerived::MyDerived
: MyDerived::Incredible(params)
{}

.

+7

using typedef, " ", using /.

#include <map>

template <typename ...>
class foo
 {};

struct A : public foo<int, std::tuple<long, char, std::map<std::string, int>>>
 {
   using base_t = foo<int, std::tuple<long, char, std::map<std::string, int>>>;

   A () : base_t{}
    { };
 };

int main()
 { } 
0

Source: https://habr.com/ru/post/1654139/


All Articles