最近,我工作的一个代码,发现下面的代码:比较的CComBSTR为NULL
CComBSTR userName;
SUCCEED(getUserName(userName));
if(userName == NULL) ...
最后一行提醒我,因为我反对NULL
这是不直观比较的对象。但在MSDN一眼后,这是完全支持:
bool operator ==(const CComBSTR& bstrSrc) const throw();
bool operator ==(LPCOLESTR pszSrc) const;
bool operator ==(LPCSTR pszSrc ) const;
bool operator ==( int nNull ) const throw();
所以我的问题是,为什么会API的CComBSTR
设计允许这样的比较?只是为了更容忍错误?
BSTR是一个指针类型。指针可以是NULL。 – 2013-05-10 07:29:51
@HansPassant有道理。谢谢! – Archer 2013-05-13 02:58:05