Why should I use new and not malloc()?

Just got a Mail from a user asking for a question as and thought also after answering him would like to share the same with Expert Advice Forums member

Why should I use new and not malloc()?

» Constructors/destructors:
New and Delete makes sure that constructors and Destructors are called but not the case with malloc and free functions of C.
» Pointer conversion safety:
malloc() returns a void* which isn't safe. new returns a pointer of the right type.
» new is a Operator:
new is an operator that can be overloaded for better memory management by a class, while malloc() is not an operaotor.

The compiler will implicitly define a default constructor if no constructors are explicitly defined for a class. This implicitly-declared default constructor is equivalent to a default constructor defined with a blank body. (Note: if some constructors are defined, but they are all non-default, the compiler will not implicitly define a default constructor. This means that a default constructor may not exist for a class.)

To create a class that cannot be instantiated with new you need to declare a private constructor. Of course, you will need to pair this with a friend class that will be able to create objects, otherwise you won't be able to create any objects of the first type at all, which would be rather pointless.