函数重载的一个怪异的现象
以下是函数重载的声明:
//--------------------------------------------------------------------
// Summary:
// 设置属性值
// Parameters:
// [in] szAttrName - 属性名称
// [in] szAttrValue - 属性值
//--------------------------------------------------------------------
um_ReturnCode SetAttribute(LPCumWSTR szAttrName, LPCumWSTR szAttrValue);
um_ReturnCode SetAttribute(const CumString& strAttrName, um_INT nAttrValue);
um_ReturnCode SetAttribute(const CumString& strAttrName, um_BOOL bAttrValue);
um_ReturnCode SetAttribute(const CumString& strAttrName, um_ID idAttrValue);
um_ReturnCode SetAttribute(const CumString& strAttrName, um_FLOAT fAttrValue);
um_ReturnCode SetAttribute(const CumString& strAttrName, um_DOUBLE dAttrValue);
如果我在CPP文件中这样调用SetAttribute()
pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, 0);
或者
pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, (um_INT)0);
都会出现下面的错误:
error C2666: 'CXMLDOMNode::SetAttribute' : 6 overloads have similar conversions
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(389): could be 'um_ReturnCode CXMLDOMNode::SetAttribute(const CumString &,um_DOUBLE)'
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(388): or 'um_ReturnCode CXMLDOMNode::SetAttribute(const CumString &,um_FLOAT)'
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(387): or 'um_ReturnCode CXMLDOMNode::SetAttribute(const CumString &,um_ID)'
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(386): or 'um_ReturnCode CXMLDOMNode::SetAttribute(const CumString &,um_BOOL)'
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(385): or 'um_ReturnCode CXMLDOMNode::SetAttribute(const CumString &,um_INT)'
2> f:\office\trunk\__internal\headers\umbase\XMLDOMNode.h(379): or 'um_ReturnCode CXMLDOMNode::SetAttribute(LPCumWSTR,LPCumWSTR)'
2> while trying to match the argument list '(const wchar_t [4], um_INT)'
但是如果我这样写就不会出错:
pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, 1);
我的疑问是以下几点:
(1)为什么pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, 1);正确,而
pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, 0);错误?
(2)为什么强制转换后,pNodeCrossRef->SetAttribute(XML_ATTR_DISPTYPE, (um_INT)0);依然错误?
请问造成以上现象的根源是什么?