Possible duplicate:The most unpleasant parsing: why A a (()); work?
I have this simple problem in C ++ that forces me to renew my CS degree again, trying to learn something this time.;)
Why this code does not compile:
vector<int> v(int()); v.push_back(1);
while this other compiles without warning
vector<int> v((int())); v.push_back(1);
It’s hard to find the difference at all (additional brackets added: P).
He called the most unpleasant parsing.
vector<int> v(int());
v, ( , int) vector<int>. "" v, ( , int) a vector<int>.
v
int
vector<int>
, , (int()) v.
(int())
++ , ( int()) , , ( ) .
int()
, . .: http://www.gotw.ca/gotw/075.htm