c++ - Comparing CComBSTR to NULL -


lately, working on code , found following code:

ccombstr username; succeed(getusername(username)); if(username == null) ... 

the last line alerts me, since i'm comparing object against null not intuitive. after glance on msdn, supported:

bool operator ==( const ccombstr& bstrsrc ) const throw( );  bool operator ==( lpcolestr pszsrc ) const;  bool operator ==( lpcstr pszsrc    ) const;      bool operator ==(  int nnull  ) const throw( ); 

so question is, why api design of ccombstr allow such comparison? more tolerant errors?

a smart pointer designed , intended mimic raw pointer as possible, provide automatic memory management otherwise transparent outside code. means overriding ->, =, , & operators, implementing conversion operations, etc. way, rest of code can treat smart pointer if real pointer in aspects.

imagine started code:

bstr username; succeed(getusername(&username)); if(username == null) ... 

then wanted upgrade smart pointer:

ccombstr username; succeed(getusername(&username)); if(username == null) ... 

see how works? 1 line changed.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -