There is a template class A:
template<typename T>
class A {
public:
T t;
A(T t) {
this->t = t;
cout << "A constructor" << endl;
}
~A() {
cout << "A destructor" << endl;
}
};
t is the member of class A, what if t is a pointer points to dynamically allocated memory so that the default destructor can't free it, for example:
A<SomeType*> a(new SomeType());
Because we don't know if t is a pointer or not, so we can't just make the deconstructor like this:
~A() {
delete t;
cout << "A destructor" << endl;
}
My question is how to guarantee that there is no memory leak no matter t is a pointer or not