Reputation: 1
vector<double> salaries();
vector<double> salaries;
I wanted to declare a empty vectors and above two declarations are possible as compiler returned no error. What is the difference between two above declarations?
Upvotes: 0
Views: 58
Reputation: 62379
With the update, the two declarations you show are:
Note that (1) is sometimes written with the intention of doing the same thing as (2) (i.e. using the default constructor). But that's not how the compiler sees it - this is often referred to as a "most vexing parse", which you should be able to find much more information on with a little searching. Basically, though, it's an (intentional) ambiguity in the language syntax, that is resolved by the language specs by requiring that particular syntax to be treated as a function, but still surprises a lot of people.
Upvotes: 1