+ 5

Object of class

What is difference between below line of code? Assume A is class name and a is object. now, does A a; and A a(); are same? First one is nothing but default constructor...What does second object represents?

3rd Apr 2018, 6:20 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
4 RĂ©ponses
+ 3
it doesn't call default A a if we declare object like A a(). try simple code and you may observe it...
9th Apr 2018, 3:04 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 2
A a; A a(); and A a{}; are all the same, but the last one is the default C++ way to define something, it implicitly makes more checks and it is more strict. Appart from that, when doing A a; by default, it calls the default constructor A a(); unless otherwise specified. More info on this: https://www.quora.com/Whats-the-difference-between-brace-and-parentheses-initialization-in-C++11
3rd Apr 2018, 7:24 PM
Bebida Roja
Bebida Roja - avatar
+ 2
Ketan Lalcheta it looks like it is not proper way to define a object. First I thought maybe compiler have generated temporary object but it is not. I have verified it through default constructor, parameterized constructor with default argumnet and also with copy constructor but it is showing non class of type. here is my sample code. https://code.sololearn.com/cMCycvHWqX7G/?ref=app
30th May 2018, 9:37 AM
$±𝐎â‚č𝔭!𝐹𝓝
$±𝐎â‚č𝔭!𝐹𝓝 - avatar
- 1
duplicate. based on what you use to compile the code.
14th Apr 2018, 11:22 PM
Johnno Johnathan
Johnno Johnathan - avatar