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?
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) (ie 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.