'Introducing base class constructor into the derived implementation with 'using' does not allow converting base to derived

It's a mouthful to describe the problem with words, in code it's much simpler:

template <typename T>
struct Vec2
{
    Vec2() = default;
    Vec2(const Vec2&) = default;
};

template <class T>
struct Point : public Vec2<T>
{
    using Vec2<T>::Vec2;
};

void f(const Point<float>&);

void test()
{
    f(Vec2<float>{});
}
  • Vec2<T> has a copy constructor.
  • Point<float> is derived from Vec2<float> and pulls in its constructors.

Expected: Point<float> should be constructible from Vec2<float>.
Reality: "No known conversion" error (https://godbolt.org/z/boe86f99K). Why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source