new T vs new T() | Sololearn: Learn to code for FREE!


new T vs new T()

Hi If I am not wrong , new T doesnot call constructor for our own defined class. It's like malloc just memory allocation.... To have constructor call , we need to create object using new T();... Such happens when we have defined our own constructor... If constructor is from compiler, there is no difference between new T and new T()... Is above correct ? However, I am not getting any difference for both type of object in both classes with or without our own constructor. Below is code: Conclusion : what is difference between new T and new T()

6/25/2020 10:47:50 AM

Ketan Lalcheta

4 Answers

New Answer


There is a difference between C++98 and C++03 and up.


No your understanding is not correct. In both cases the default constructor will be called. There is no difference between the 2 constructs


Oh okay I didn't know that


So is it good I mean safe to go with new T() over new T in any version of compiler for any case of class.... Isn't it ? I used to define new T till the date be it any compiler version...