Quote Originally Posted by matsp View Post
new is also an operator, but I was more thinking of what happens inside the code after the compiler has done it's job.

For example, we can imagine a compiler that compiles this:
Code:
class A 
{
   ... 
};

...
   A *a = new A;
...
could conceivably be generated as (written in C - it would naturally be machine code when the compiler is done with it):
Code:
    a = malloc(sizeof(A));
    a->A();  // call constructor.
--
Mats

Quite true, matsp. Though I would not advise anyone make codes that take this piece of trivia as a universal rule.

Example:
Code:
int *x = new int;
free(x);
Example:
Code:
int *x = reinterpet_cast<int *>(malloc(sizeof(*x)));
int *y = new y;

free(x);
delete y;
Note: That is for the benefit of the OP and other people with similar misconceptions, not matsp who is well aware of these facts. It is important that people know by design you should not mix and match your C and C++ dynamic memory allocations.