I have problems understanding the correct behavior of inheriting constructors from a base class. In my particular case, I have a crtp-base class with private constructors in order to prevent an instantiation of the base class (as abstract class). Now, the crtp-base befriends the derived class and the derived class inherits the base class constructors with a using statement. This works well for the default, copy and move constructor but fails for custom constructors. Is there a way to achieve this without reimplenting all constructors in the derived class?
#include <iostream>
template <typename d_t>
class base
{
friend d_t;
base()
{
std::cout << "base: ctor()\n";
}
base(base const & other) = default;
base(base && other) = default;
base(int)
{
std::cout << "base: ctor()\n";
}
};
class derived: public base<derived>
{
public:
using base<derived>::base;
};
int main()
{
derived d{};
derived d1{d};
derived d2{std::move(d1)};
// derived d3{1}; //does not compile!
}
EDIT
AFAIK cppreference says that accessibility of constructors is not changed by the access specifier of the using declaration in the derived class, which is different to other member functions. But I have seen this kind of code compiling and running and I am not sure if I understood the using-declaration correctly. Of course I'll investigate the other code further to see what is going on but I wanted to know if there is something hidden that I might miss.