the “new” operator in c++, pointer question

后端 未结 5 1309
说谎
说谎 2021-02-19 17:53

Dumb question, but whenever you call new, do you always have a pointer?

SomeClass *person = new SomeClass();

And is that because you need a poi

5条回答
  •  自闭症患者
    2021-02-19 18:45

    If new completes successfully, it always returns a pointer (if it doesn't complete successfully, an exception is thrown, and nothing is returned).

    The pointer is to the object that was created, or in the case of an array, a pointer to the first element of the array.

提交回复
热议问题