I assume this is because T && is a universal reference ...
Wrong. T&& not a universal (forwarding) link in this case. T&& is just the rvalue reference to T Universal / redirect links should be displayed.
... and because of the rules for collapsing links, the second constructor is also converted to the same signature as the first.
It is right. Our two designers accept:
T const& ==> A const& const& ==> A const& T&& ==> A const& && ==> A const&
hence the error of overriding.
Depending on what you want to do, only std::decay T might be a simple solution:
template <typename T> class MyClass { using DecT = typename std::decay<T>::type; public: MyClass(const DecT& ); MyClass(DecT&& ); };
In your example, it will still create a class with two constructors: one takes const A& , and the other takes A&& .
Barry source share