To avoid, if u must use pointer in class, u can:
1. everytime use this class type as parameter, pass it by pointer or reference (can make a private copy constructor to ensure it)
2. or implement ur own copy constructor, when copy, alloc another heap for the created new instance
3. or use some kind of smart pointer (keep monitoring the reference counter of the pointor, if it's 0 then do the real deletion)
Also, a good programming style: assign null to pointer after operator delete, and check if the pointor is null b4 u delete it
This post has been archived. It cannot be replied.