为什么提示ambiguous,该怎么解决
template<class TYPE>
class CType
{
public:
CType() {
data = 0;
}
CType(const CType& type) {
data = type.data;
}
~CType() {
data = 0;
}
operator TYPE&() {
return data;
}
protected:
TYPE data;
};
typedef CType<DWORD> CDWord;
执行代码:
CDWord dw;
DWORD dw2;
dw2 = dw; // error C2593: 'operator =' is ambiguous
dw = dw2; // error C2593: 'operator =' is ambiguous
vc6.0 + sp6环境下编译会有如上出错提示
下面这样写没有,不过已经违背了我设计这个类的初衷
(DWORD&)dw2 = dw; // OK
dw = (DWORD&)dw2; // OK