Given this class hierarchy:
#include <iostream>
class Base {
public:
Base() = default;
Base(const Base&) { std::cout << " copy\n"; }
template<typename T>
Base(T&&) { std::cout << " T&&\n"; }
};
class Sub : public Base {
public:
using Base::Base;
};
It is known that this code would print T&&:
// objects
Base varObj;
const Base constObj;
// invoking constructors
Base copy(varObj); // T&&
Base move(std::move(constObj)); // T&&
Base number(42); // T&&
Why does using Sub instead of Base "fix" the problem?
// objects
Sub varObj;
const Sub constObj;
// invoking constructors
Sub copy(varObj); // copy
Sub move(std::move(constObj)); // copy
Sub number(42); // T&&