Can I use malloc in place of new while creating object for my class in c++?
yes, as both are same.
no, because malloc don't know to call constructors.
no, because it gives compile time error.
It is not wise to use malloc while creating objects for your class. Because malloc don't know to call constructors while creating objects. Where as new operator will allocate memory like malloc, and it will call constructors to initialize all the variables.
Back To Top