一、陷阱1
class A
{
public:
bool Add(LPCTSTR strKey, const CString &strValue);
bool Add(LPCTSTR strKey, const bool bValue);
}
当调用
A a;
a.Add("abc", "11123");
你猜会发生什么
编译居然调用了bool参数匹配!!!
bool Add(LPCTSTR strKey, const bool bValue);
解决方案:
bool Add(LPCTSTR strKey, const CString &strValue);
bool Add(LPCTSTR strKey, LPCTSTR strValue);
二、陷阱2
class A
{
public:
bool Add(LPCTSTR strKey, const A &Object);
bool Add(LPCTSTR strKey, LPCTSTR strValue);
}
CString str = "1122";
A a;
a.Add("abc", str);
编译居然调用了第一个参数匹配!!!
奇葩的c++编译优化行为
参考解决方案: