Understanding the C ++ Compiler

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).

+5
source share
2 answers

He called the most unpleasant parsing.

vector<int> v(int());

v, ( , int) vector<int>. "" v, ( , int) a vector<int>.

, , (int()) v.

++ , ( int()) , , ( ) .

+9
+1

All Articles