Foo f();
This is a form of what is known as the Most Vexing Parse. If you are instantiating an automatic variable with its default constructor, there is no need to have the ()
.
Foo f;
If you need to call a different constructor, use the ()
:
Foo f(some other data);
Or the newer initialization syntax (C++11):
Foo f { some other data };
Details
Scott Meyers talks about this in Item 6 of "Effective STL". The basic rule for C++ is that if a line can be parsed as a function declaration, it will be. This means that both of the following lines are parsed as function declarations, not variable instantiations:
Foo f(); // declares a function f that takes no parameters and returns a Foo
list<int> data(istream_iterator<int>(dataFile), istream_iterator<int>()); // declares a function that takes 2 istream_iterators and returns a list<int>