1
Почему делегирование конструкторов не выполняется в случае шаблонов? Конструктор копирования не вызывает конструктор константной копии в случае T=U
, хотя без этого template <typename U>
и <U>
он работает.Делегирование конструкторов и шаблонов
template <typename T>
struct Class {
Class() {
std::cout << "Default constructor" << std::endl;
}
template <typename U>
Class (const Class<U>& rhs) {
std::cout << "Const copy constructor" << std::endl;
}
template <typename U>
Class (Class<U>& rhs)
: Class (const_cast<const Class<U>&> (rhs))
{
std::cout << "Copy constructor (templated)" << std::endl;
}
/* // DOES NOT WORK WITHOUT THE NEXT:
Class (Class& rhs)
: Class (const_cast<const Class&> (rhs))
{
std::cout << "Copy constructor (not templated)" << std::endl;
}
*/
};
[Работы для меня] (http://coliru.stacked-crooked.com/a/18c2a8ffd206f55f) –
@AntonSavin, да, но не с Т = U. – se0808
@ DieterLücking, даже без шаблона '? –
se0808