Possible Duplicate:
Why is it an error to use an empty set of brackets to call a constructor with no arguments?
The small piece code code can not be successfully compiled on
Microsoft Visual Studio 2005
#include <iterator>
#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
std::vector<int> a;
std::istream_iterator<int> be(std::cin);
std::istream_iterator<int> en();
std::copy(be, en, std::back_inserter(a));
}
But this one is ok
#include <iterator>
#include <algorithm>
#include <vector>
#include <iostream>
int main()
{
std::vector<int> a;
std::istream_iterator<int> be(std::cin);
std::istream_iterator<int> en; //Same to upon, only here less '()'
std::copy(be, en, std::back_inserter(a));
}
In the first case
enis being declared as a function, not a variable. This is one of the many traps present in C++ syntax that makes hard to parse a C++ program.The rule applied is more or less “if it can be parsed both as a declaration or as a definition then it’s considered a declaration” and has been named “most vexing parse” by Scott Meyers. In your case the second line can be seen similar to
And is therefore considered a function declaration. Note that this very same trap can be even more subtle:
here the second line is also a declaration for a function because language rules says here that the parenthesis around
xcan be ignored and therefore the meaning isint y(int x);.