0
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: https://code.sololearn.com/c320BMUYeZxq/?ref=app Conclusion : what is difference between new T and new T()
4 Answers
+ 3
There is a difference between C++98 and C++03 and up.
https://stackoverflow.com/questions/620137/do-the-parentheses-after-the-type-name-make-a-difference-with-new
0
No your understanding is not correct.
In both cases the default constructor will be called.
There is no difference between the 2 constructs
0
Oh okay I didn't know that
0
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...