c++ - Comparing CString to TCHAR by ==? -
i have cstring pointer , being compared tchar in following way:
if(srttest[i] == _t('\n')) //do
where strtest cstring* strtest;
i wonder if correct, considering not tchar-pointer. compiles ok. code old , no 1 seems have complained it, makes me wonder though.
yes, it's ok (assuming strtest
valid pointer , i
valid index). since strtest
cstring*
, strtest[i]
cstring
. , there free operator==
overload accepts const cstring&
param1 , lpctstr
param2 , you'd expect.
the msdn documentation here. second overload 1 matters:
bool operator ==( const cstring& s1, lpctstr s2 );
(the documentation out of date , signature see when trace actual code different, effect same)
markransom alerted me fact code compares strtest[i]
character rather string. that's still ok, because there operator==
overload takes cstring
/char
. it's not listed in documentation linked to, here's actual code looks in vs2012 version:
friend bool operator==( _in_ const cstringt& str1, _in_ xchar ch2) throw() { return( (str1.getlength() == 1) && (str1[0] == ch2) ); }
since it's not listed in outdated documentation, function presumably did not exist. however, cstring
has implicit constructor takes tchar
. assume in vc++ versions predate above, cstring
implicitly constructed _t('\n')
, used in call cstring
/cstring
overload of operator==
.
Comments
Post a Comment