Possible Duplicate:
different types of initialization in C++
Is there any difference at all between calling the base constructor like
Foo afoo;
vs
Foo afoo();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes: the first is a variable definition, the second is a function declaration. Now lets discuss the more interesting question of the difference between these two expressions:
Whether there is a difference depends on the type of
Fooand its members!Foohas an explicit default constructor the two are identicalNote that this also applies to members of classes. For variables you cannot use the form using parenthesis, i.e. to make sure the object is initialized you need to use
If there is no explicit constructor taking an argument or you don’t know (e.g. in template code).