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
This question deals with AVL trees. The representation to be used is similar to the bank account object discussed in class. (a) Define a procedure called make-avl-tree which mak

Define the Data File in C Programming? Many applications needs that information can written to or read from an auxiliary memory device. Such information is stock up on the memo

P o i n t e r d e c l a r a t i o n f o r d a t a m e m b e r : M e t h o d 1 : i n t M : : * p x ; / / T h i s

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Multidimensional Arrays - Every dimension is specified in separate brackets e.g. int arr[4][3]; This is a two-dimensional array with 4 as row dimension and 3 as

what is the function of spanning tree in graph algorithm?

In general, Roman numerals can be converted mathematically by simply assigning a numerical value to each letter, according to the chart below, and calculating a total: M=1000 | D=5

Prepare a MT4 EA to clone MT4 Trades to a Binary Options Platform Project Description: I want an EA that clones MT4 Trades to Globaltrader365, GT Options and if possible othe

#At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with the

Program to define an array in c: Write a program to define an array and print the value of array. void main() { int a[10]={0,11,21,34,44,75,46,57,88,89},i,j,k; clr