0

In order to avoid the Most Vexing Parse I added extra parentheses here:

std::vector<int> v(std::istream_iterator<int>(inp), (std::istream_iterator<int>()));

Where inp is an istringstream created from a std::string.

But why do the extra parentheses work? Why doesn't the compiler ignore them as redundant?

TRPh
  • 187
  • 1
  • 9
  • 3
    Because it's not a valid way to declare a function. Function declaration syntax is not an "operation" where parenthesis mean order of operation. It's syntactically invalid to have them in that position of a function declaration. So then it must be a function call and only after that's determined are they processed and essentially discarded. – xaxxon Feb 03 '21 at 22:12
  • 1
    Does this answer your question? [A confusing detail about the Most Vexing Parse](https://stackoverflow.com/questions/7007817/a-confusing-detail-about-the-most-vexing-parse) – Richard Critten Feb 03 '21 at 22:13
  • 2
    With regards to the duplicate target, read this answer: https://stackoverflow.com/a/23726218/4342498 – NathanOliver Feb 03 '21 at 22:13

0 Answers0