The next few lines I'm going to write come from the book "The C++ Standard Library - A tutorial and reference".
Initialize by using standard input:
//read all integer elements of the deque from standard input
std::deque<int> c((std::istream_iterator<int>(std::cin)),
(std::istream_iterator<int>()));
Don't forget the extra parentheses around the initializer arguments here. Otherwise, this expression does something very different and you probably will get some strange warnings or errors in following statements. Consider writing the statement without extra parentheses:
std::deque<int> c(std::istream_iterator<int>(std::cin),
std::istream_iterator<int>());
In this case, c declares a function with a return type that is deque. Its first parameter is of type istream_iterator with the name cin, and its second unnamed parameter is of type "function taking no arguments returning istream_iterator." This construct is valid syntactically as either a declaration or an expression. So, according to language rules, it is treated as a declaration. The extra parentheses force the initializer not to match the syntax of a declaration.
I can see why the one with extra parentheses is not considered a function declaration, but
I can't see what would make the one without into a function declaration though? For it has parentheses around (std::cin)
, and as far as I know variables may not have names with parentheses?
Am I missing something?