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
#q•Design and code a new function that accepts as parameters the gross pay by value and the federal tax, state tax, local tax, SS tax, and net Pay by reference. Calculate the taxes

Define a structure of student class:  Write a program to define a structure of student record in C. class student { char name[20]; int roll_no; int marks[2];

I am working on a program that allows a player to play a game against the computer. In this game the player can only chose to draw 1, 2, or 3 toothpicks. How do I make restrictions

Write algorithm and program for the conversion of a Tree to a Binary Tree


kirchoff''s law

WAP TO ACCEPT THE BASIC SALARY OF EMPLOYEES & CALCULATE NET SALARY   #include stdio.h> #include conio.h>   void main() {                    float Basi

Develop a Student class that has the following header file: #ifndef STUDENT_H #define STUDENT_H #include #include #include using namespace std; class Stu

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send