can someone explain the new keyword to me and how to use it? im confused by it! thanks
can someone explain the new keyword to me and how to use it? im confused by it! thanks
It creates a new object of type
new int;
new class;
Marky_Mark
Last edited by Marky_Mark; 10-30-2001 at 04:07 PM.
no it doesn't......
new is basically c++ version of malloc(). It is used to ask the OS for some memory.It returns a pointer to that memory if successful and if not it returns NULL.new is used only for dynamic memory allocation. It is an operator that can be overloaded.The big difference between new and malloc is that new will call pertinent constructors whereas malloc wont.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Cool, so what is the new keyword? I didn't think they were going to update until 2002.can someone explain the new keyword to me and how to use it?
Originally posted by Stoned_Coder
no it doesn't......
new is basically c++ version of malloc(). It is used to ask the OS for some memory.It returns a pointer to that memory if successful and if not it returns NULL.new is used only for dynamic memory allocation. It is an operator that can be overloaded.The big difference between new and malloc is that new will call pertinent constructors whereas malloc wont.
Thanks for the detailed explaination, but it still creates
a new instantiation of a particular type of object
that's how i use it anyway
Marky_Mark
Last edited by Marky_Mark; 10-31-2001 at 09:15 AM.
Constructors are called as usual, after the allocation
function is finished
Marky_Mark
what would be an appropriate use for new?
new is used for dynamic memory allocation. If I don't know how much memory I'll need before I start, I'll need to consume memory as needed. A good example would be a linked list, typically I don't know how big the list is before I start so I use new to create nodes for the list as required.