Home > Software engineering >  Does "new CLASS" return CLASS or CLASS*
Does "new CLASS" return CLASS or CLASS*

Time:05-10

I don't know what details to give other than the title, but I'm happy to give more if anyone needs any before answering the question. This may seem really simple, but I don't know how to actually make a program that tells me this.

CodePudding user response:

As stated in comments, new will always give you a pointer.

But as new implies delete, I strongly advise you to take a look at a concept call RAII, especially why it's so popular.

CodePudding user response:

Does "new CLASS" return CLASS or CLASS*

It returns a pointer to the type of the object that you're trying to allocate.

From new expression:

The new expression attempts to allocate storage and then attempts to construct and initialize either a single unnamed object, or an unnamed array of objects in the allocated storage. The new-expression returns a prvalue pointer to the constructed object or, if an array of objects was constructed, a pointer to the initial element of the array.

  • Related