Difference between Object var and Object* var = new Object()

后端 未结 5 1034
醉酒成梦
醉酒成梦 2021-01-20 00:24

If I have a class named Object, what\'s the difference between creating an instance just like that:

Object var;

and:

Object         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 01:07

    This:

    Object var();
    

    Is a function declaration. It declares a function that takes no arguments and returns an Object. What you meant was:

    Object var;
    

    which, as others noted, creates a variable with automatic storage duration (a.k.a, on the stack).

提交回复
热议问题