What is the difference between Object b(); and Object b;?

后端 未结 5 1800
执念已碎
执念已碎 2021-01-23 07:49

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

5条回答
  •  不知归路
    2021-01-23 08:45

    "Object b();" declares a function b() returning an object of type Object, while "Object b;" defines a variable b of type Object.

    No, it's not obvious, and it still comes back to bite me if I switch between C++, Java, and C#. :-)

提交回复
热议问题