(e-mail address removed) yazdi:
hi r.z,
as clearly mentioned in the above documentation, use this Tab class
only for the object data types and not for pointer datatypes.
A Tab class object releases the resources allocated with the Tab object
itself and DOES NOT releases the resources pointed by the pointers
stored in it.
If you still want to store the pointers to the objects you have to
manually call destructor on the pointers stored in the Tab class by
iterating over the Tab class object. But even then u have to take care
when u are assigning one tab object to another one.
I had to do something like this. Here is a trick:
Wrap the pointer with a non-destructive class
template <class Ptr>
class NDPtr
{
Ptr* p;
public:
template <class Ptr> NDPtr(const Ptr* p_=0) {p=p_;}
template <class Ptr> NDPtr(const Ptr& r) {p=r.p;}
template <class Ptr> void operator=(const Ptr& r) {p=r.p;}
template <class Ptr> ~NDPtr() {/*NOTHING, See Below*/}
....
};
Then make a destructive class which has nothing but a destructor that
deletes the wrapped pointer.
template <class Ptr>
class DPtr : public NDPtr<Ptr>
{
public:
template <class Ptr> ~DPtr() { if(p) delete p;}
}
NDPtr<Type> can be used with Tab class or with any container class.
For example
set<NDPtr<char> > objCharPtrSet;
// use it as long as you want
And when you want to delete all the pointers do this:
// we should treat NDPtr as DPtr
// to delete the wrapped pointer.
set<DPtr<char> >& r = (set<DPtr<char> >&) objCharPtrSet;
// call clear to delete all the pointers
r.clear();