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

Assignment Help:

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.

 


Related Discussions:- Why should i employ new instead of truthful old malloc()?

We want database development, Presently we are using several spreadsheets t...

Presently we are using several spreadsheets to give weekly activity and income reports. Much of the information is being frequently re-keyed into several spreadsheets - we are look

Is always the default constructor for fred fred::fred()?, Is always the def...

Is always the default constructor for Fred Fred::Fred()?

How to use http headers inside php, How to use HTTP Headers inside PHP? Wri...

How to use HTTP Headers inside PHP? Write the statement through which it can be added? HTTP headers can be used in PHP by redirection that is written as: Headers can be

Described inline function?, A: The inline keyword tells the compiler to sub...

A: The inline keyword tells the compiler to substitute the code in the function de_nition for each instance of a function call. Though, substitution takes place only at the compile

What is a hash function, What is a hash function? Hash function: This ...

What is a hash function? Hash function: This is the method from the set 'K' of keys into the set 'L' of memory addresses.   H: K → L These are used to verify the address

Solution, 3 . Write a ‘C’ program to accept any 3 digit integer numb...

3 . Write a ‘C’ program to accept any 3 digit integer number from the keyboard and display the word equivalent representation of the given number.

Should i call a destructor explicitly on a local variable?, Should I call a...

Should I call a destructor explicitly on a local variable?

Area under the curve, program area under the curve y=f(x) between x=a & y=b...

program area under the curve y=f(x) between x=a & y=b, integrate y=f(x) between the limits of a & b   Solution: #include float    start_point,            /* GLOBAL V

Write a c program as text layout, Your task in this project is to write a C...

Your task in this project is to write a C program named layout.c which does text layout. This is a staged project, complete the stages in order. The maximum mark if you nish each

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd