Creating a class object in c++

前端 未结 8 2173
离开以前
离开以前 2020-12-07 11:08

First i am from JAVA.

In java we create class object like this.

Example example=new Example();

The Example class can have constructor

8条回答
  •  被撕碎了的回忆
    2020-12-07 11:56

    1) What is the difference between both the way of creating class objects.

    a) pointer

    Example* example=new Example();
    // you get a pointer, and when you finish it use, you have to delete it:
    
    delete example;
    

    b) Simple declaration

    Example example;
    

    you get a variable, not a pointer, and it will be destroyed out of scope it was declared.

    2) Singleton C++

    This SO question may helps you

提交回复
热议问题