Thursday, July 9, 2009

Can you write pointer constructors & destructors in C++?If so, can you create / destroy the referenced object?

If you can, could a pointer not be used to help with automatic memory management, since creating the pointer could allocate memory for %26amp; create the object, and destroying it would free the memory and destroy the object? You could just create, manipulate and destroy things using pointers the same as you do with Java object references. Or am I missing something?

Can you write pointer constructors %26amp; destructors in C++?If so, can you create / destroy the referenced object?
This is a very very complicated subject. No, really. The best way of approaching it is to google 'smart pointers c++' which will give you many useful articles.





A smart pointer is sorta what you alluded to in your question. But it's complex and, I might say, is one of the reasons why java/c# is rather superior (i.e. garbage collection, memory management). But that's just my opinion.


No comments:

Post a Comment