Jan 17, 2009

In a class, the new operator is used for allocating memory for objects created . Can this be done using malloc ? If yes, how and if no , why not ? Are

In a class, the new operator is used for allocating memory for objects created . Can this be done using malloc ? If yes, how and if no , why not ? Are there any restrictions associated with the use of malloc in place of new ?
The difference between "new" and "malloc" is that, if you use new, you are not only allocate the memory for the object, but also call the constructor for the object.
If you "new" the class, the constructor code will be called, if you use malloc, only memory for the class will be allocated, no constructor code will be called.

No comments:

Post a Comment