I suggest you use std::unique_ptr for T when you need Example to store a pointer to the owner. If T is a raw pointer, then it simply does not own it and should not delete it.
If you need Example initialize the pointer, highlight it for std::unique_ptr and call std::make_unique in the default constructor.
template<typename T> class Example<std::unique_ptr<T>> { Example() : data{std::make_unique<T>()} {} };
If you do this, you should not specialize your class for T* to make new , since you cannot initialize pointers without ownership. You should get it in the constructor and possibly turn off the default constructor for raw pointers if you don't want it to be null.
template<typename T> class Example<T*> { Example() = delete; Example(T* data_) : data{data_} };
If you follow these rules, you should not have problems with memory management.
source share