?
=?iso-8859-1?q?Ernesto_Basc=F3n?=
I am implementing my custom smart pointer:
template <typename T>
class MySmartPtr
{
public:
MySmartPtr(T* aPointer)
{
mPointer = aPointer;
}
inline T* operator->() const {return mPointer; }
private:
T* mPointer;
};
It could be used in this way:
MySmartPtr<A> obj = new A();
obj->Method1();
int value = obj->Method2();
The operator-> overload allows accessing the A methods as they are
accessed via a common pointer.
I want to allow the final user call the delete operator as in a common
pointer when he wants to explicitly remove the pointer:
delete obj;
There is a way I could implement an overload of the delete pointer in
my MySmartPtr<T> or there is some workaround on this?
Thanks in advance,
ernesto
template <typename T>
class MySmartPtr
{
public:
MySmartPtr(T* aPointer)
{
mPointer = aPointer;
}
inline T* operator->() const {return mPointer; }
private:
T* mPointer;
};
It could be used in this way:
MySmartPtr<A> obj = new A();
obj->Method1();
int value = obj->Method2();
The operator-> overload allows accessing the A methods as they are
accessed via a common pointer.
I want to allow the final user call the delete operator as in a common
pointer when he wants to explicitly remove the pointer:
delete obj;
There is a way I could implement an overload of the delete pointer in
my MySmartPtr<T> or there is some workaround on this?
Thanks in advance,
ernesto