c++ - Infix vs prefix syntax: name lookup differences -


operators in c++ considered alternative syntax functions/methods, in context of overloading. if so, 2 expressions below should synonymous:

std::cout << 42; operator<<(std::cout, 42); 

in practise, second statement leads following error:

call of overloaded ‘operator<<(std::ostream&, int)’ ambiguous 

as usual, such error message accompanied list of possible candidates, these are:

operator<<(basic_ostream<_chart, _traits>& __out, char __c) operator<<(basic_ostream<char, _traits>& __out, char __c) operator<<(basic_ostream<char, _traits>& __out, signed char __c) operator<<(basic_ostream<char, _traits>& __out, unsigned char __c) 

such error raises @ least 2 questions:

  1. in way 2 statements different (in terms of name lookup)?
  2. why operator<<(basic_ostream<char, _traits>& __out,int__c) missing?

it seems, infix , prefix notations not interchangeable -- different syntax entails different name resolution tactics. differences , did come from?

no, 2 expressions should not synonymous. std::cout << 42 looked both operator<<(std::cout, 42) , std::cout.operator<<(42). both lookups produce viable candidates, second 1 better match.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -