why should i employ new instead of truthful old


Why should I employ new instead of truthful old malloc()?

A: Constructors/destructors, type safety, overridability.

Constructors/destructors: unlike malloc(sizeof(Fred)), new Fred() calls Fred's constructor. Likewise, delete p calls *p's destructor.Type safety: malloc() returns a void* that isn't type safe. new Fred() returns pointer of right type (a Fred*).

Overridability: new is an operator which can be overridden by a class, whereas malloc() is not overridable on a per-class basis.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: why should i employ new instead of truthful old
Reference No:- TGS0217519

Expected delivery within 24 Hours