Why should i employ new instead of truthful old malloc()?, C/C++ Programming

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.

 

Posted Date: 3/19/2013 8:28:43 AM | Location : United States







Related Discussions:- Why should i employ new instead of truthful old malloc()?, Assignment Help, Ask Question on Why should i employ new instead of truthful old malloc()?, Get Answer, Expert's Help, Why should i employ new instead of truthful old malloc()? Discussions

Write discussion on Why should i employ new instead of truthful old malloc()?
Your posts are moderated
Related Questions
Question: (a) Write short notes on arrays. Extend your answer by putting emphasis on memory allocation. (b) Write a C++ program to input an integer n followed by n real-

Construct a console program to manage the booking of a Hotel room.


I need to include files so you can understand easier.

Set of Integers) Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100. The set is represented by an array of bools. Array element a[i] is true if in

Q: What are User Defined data types? C supports an extraordinary feature known as "type definition" that permits users to define an identifier that would represent an existing

I want a PROGRAM - Facebook auto like system to increase fans to different fanpage It has in a program that take Facebook mails and passwords from a excel file (.xlsx) for examp

The #define Directive The #define directive explains a macro which is a text string represented by a name. Whenever the pre-processor finds this name in the program, it is repl

Writing and compiling a program from a given Use Case definition. Follow the Average Temperature in Paradise

How do I allocate multidimensional arrays by new? A: There are several ways to do this, based on how flexible you wish the array sizing to be. On one acute, if you know all the