K
Kislay
Can malloc be used to create/allocate memory to an object of a class .
We use new , but can we use malloc ?
We use new , but can we use malloc ?
That's why C++ introduce "new" keyword. This is the standard method. ButMike said:Yes, but it's often insufficient.
'new' allocates memory and invokes your
object's constructor. 'malloc()' allocates
memory, and that's all.
-Mike
asm23 said:That's why C++ introduce "new" keyword. This is the standard method. But
if you can malloc and call the constructor manually, you can test it
yourself.(I bet this doesn't work well)
Can malloc be used to create/allocate memory to an object of a class .
We use new , but can we use malloc ?
On 2008-09-02 13:35:56 -0400, (e-mail address removed) said:
No, it's not required. Just most common. malloc and placement new is a
workable substitute.
Using malloc, followed by placement new, is a decidedly low-level
approach that is asking for bugs. About the only thing I'd use
placement new and placement delete for for is implementing STL-like
containers.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.