C++ using *new class, lost pointer?

Viewed 227

Curious as to why this fails. In the case where an object is returned rather than the pointer itself from using new, why is it illegal to make a pointer afterwards followed by deleting the pointer. Am I misunderstanding something with this sequence?

e.g.

Example e = *new Example();      //dereferencing the pointer to get Example object
Example* g = &e;                 //pointer pointing to e's address
delete g;                        //g is still pointer, but errors here.
1 Answers
Related