Reputation: 1925
We can initialize a container deque by using standard input like this:
deque<int> c((istream_iterator<int>(cin)),(istream_iterator<int>()));
As 《The C++ Standard Library》 describes,the extra parentheses around the initializer arguments are necessary.Without them ,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".Look the following code
deque<int> c(istream_iterator<int>(cin),istream_iterator<int>());
But teh extra parentheses force the initializer not to match the syntax of a declaration. I don't understand why the extra parentheses can make the initializer not to match syntax of a declaration.Thanks a lot.
Upvotes: 1
Views: 97
Reputation: 272802
Because the grammar defined in the C++ standard does not accept this form as a function declaration:
T name((U), (V));
Upvotes: 3