To be more explicit, I get a compile time error when I try accessing an instance variable when I create an object using (), but when I don\'t, the code compiles and runs as expe
What is the difference between Object b(); and Object b;?
The difference exists because C++ interprets that as a function being declared, instead of an object being created.
Object b;
This is the object b
of class Object
being created by means of the default constructor.
Object b();
This is the function b()
, being declared (it will be defined elsewhere) to return an object of class Object
, and no parameters.
Hope this helps.