双(?)定义模板成员操作符
double(?) definition of template member operators
如果我查看<在msvc _x0032_008的complex=">头文件中,我发现每个操作符定义都与_Other类型的模板操作加倍,例如在msvc>
_Myt& operator+=(const _Myt& _Right)
{ // add other complex
this->_Add(_Right);
return (*this);
}
template<class _Other> inline
_Myt& operator+=(const complex<_Other>& _Right)
{ // add other complex
this->_Add(_Right);
return (*this);
}
问题是为什么第二个定义单独不够?
PS:在gcc中似乎只有第二个定义,现在我不再担心了。:)
第一种情况还捕获了可转换为 _Myt
的右手边
class MyComplex {
// ...
public:
operator std::complex<double>() const;
operator std::complex<float>() const;
};
std::complex<double> i;
i += MyComplex(1,1); // Unambiguously uses the first form.
相关文章:
- 带引用类成员的赋值操作符
- 通过自增操作符访问类成员
- 用于具有const数据成员的类的move和右值赋值操作符
- 使用constness修改重载成员操作符
- 私有内部成员的操作符重载
- 在操作符[]前解引用成员指针
- 解引用操作符(*)作为类的成员函数重载时是如何工作的?
- c++操作符=类成员中有互斥对象
- c++的另一个类成员和重载操作符
- 双(?)定义模板成员操作符
- 为具有引用成员变量的类创建赋值操作符
- 在复制赋值操作符中赋值基类成员
- 从模板化的类赋值操作符访问私有成员变量
- 在静态成员数组定义中对自身使用sizeof操作符
- 为什么c++中的成员函数在对象名后用点操作符访问?
- 从成员函数调用重载操作符(静态)
- 如何检查成员操作符(类型)
- 指向成员操作符的指针
- 用int成员实现哪些操作符
- 如何处理赋值操作符和复制构造函数中的引用数据成员