malloc vs new for POD types

P

Paul

Method Man said:
pointers allocated via new?" interesting to read. Here's the partial answer
from the FAQ:

I don't see the problem with copying objects bit-by-bit. It's ok for structs
isn't it? Can someone shed some light?
Read the rest of the FAQ. For example, what if the object is
reference-counted? You don't update the reference count if you blindly copy
the object by using realloc(). Some implementations use reference counted
std::string's. If you bypass the copy-assign operators, you will
undoubtedly render the string object(s) unstable.

In general, that's why there is such a thing as a user-defined copy
constructor and assignment operator. They are there for a purpose, and that
purpose is to do something important if the object is copied or assigned.

-Paul
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,625
Members
45,322
Latest member
ClaritaMcI

Latest Threads

Top