c++ - No compilation error comparing integer with string? -


probably many, typed typo

int = 0; cout << < " "; //note '<' 

however, msvc++ compiler threw warning

warning c4552: '<' : operator has no effect; expected operator side-effect

though expected compilation error. indeed standard complaint code? implicit type conversion or overloading happen make code valid? confused whether < operator comparing string " " integer a or result of cout << a

a related post here.

the << operator has higher precedence <, parsed as

(cout << a) < " "; 

you not comparing string integer. instead, comparing return value of ostream::operator<<, std::cout itself, string literal. isn't legal (in sense has unspecified result, , not meaningful) either, clang warns:

warning: result of comparison against string literal unspecified 

the reason why compiles until c++11, std::ostream can implicitly converted void *. also, string literal of type const char[2] decays pointer of type const char *. so, < operator takes 2 pointers, permitted, although result not specified, because 2 pointers don't point same object.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -