I believe that you have something like the following:
template <typename T> struct A { T * t; operator T* () { return t; } };
You intend to "apply delete to objects of this class", so I assume that you mean:
void foo () { A<int> * p = new A<int>; delete p;
If so, then the call to delete correctly destroys the object and frees the memory allocated with the βnewβ in the previous line, and the answer to your question is βnoβ.
Since you pointed the conversion operator to a pointer, you can use delete for an object of type A<int> (unlike A<int>* ). Using delete will be applied to the result of calling the conversion operator:
void foo () { A<int> a; at = new int; delete a;
Basics of working with deletion:
The delete p expression does two different things. First, it calls the destructor for the object pointed to by p , and then frees memory. If you define the operator delete member for your class, then this will be the function that delete p will use to free memory.
In general, you define only those operators when you want to control how to allocate or free memory for dynamic objects of this class.
source share