最近,我工作的一個代碼,發現下面的代碼:比較的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