What is the difference between X x; and X x(); ?
Explanation
In first case: X x, the default constructor is called for x. Note that in second case x is not constructed with an empty set of parentheses - in fact, empty parentheses cannot be used to call the default constructor:

X x1;   // ok, default constructor called
X x2(); // oops, default constructor NOT called 
This is because the empty set of parentheses would make of x2 a function declaration instead of an object declaration: It would be a function that takes no arguments and returns a value of type X.
Source: Constructors

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты