在下面:CRTP和默认的赋值运算符
template<typename Derived>
class Base:
{
inline Derived& operator=(const Base<Derived>& x);
}
这是否声明删除默认的拷贝赋值运算符或者我有两个运营商:
inline Derived& operator=(const Base<Derived>& x);
// (declared by me)
和
inline Base<Derived>& operator=(const Base<Derived>& x);
// (declared by the compiler)
在这种情况下,当我调用函数时,编译器将如何获得正确的运算符?
只有当模板实际在代码中实例化时,它才会出现编译器错误。否则,它会编译得很好。 – SomeWittyUsername
@icepack是真的,即时假设模板实例化 –
@icepack这是不正确的。如果一个模板总是格格不入,而不管你传递了什么样的模板参数,那么模板可以被拒绝而不需要实例化。这适用于他的类模板,如果默认赋值运算符也会被实例化。 –