Create a class template SmartPointer that should contain a pointer to any object and delete that same object when the destructor of that class is called.
Does anyone knows how should i start and what should i add as a variable in this class? I tried to find something on the internet about smart pointers but i can not get it..
Then, you make it contain a single variable; a pointer.
<begin class template>
<pointer X>
<end class template>
Then, you define one method, the destructor.
<begin class template>
<pointer X>
<begin destructor>
<end destructor>
<end class template>
Then, inside that destructor, delete the data of the pointer.
<begin class template>
<pointer X>
<begin destructor>
<delete pointer X>
<end destructor>
<end class template>
Edit: Also, you aren’t using a smart pointer, you’re making one. Also, smart pointers are like std::unique_ptr, std::shared_ptr... stuff like that. You should be adding a pointer of type T* where T is the template argument.
@akash16 ... generally when you are answering a question, try not to just give someone the answer in straight up exact code. It’s not... what’s that word... em. Constructive?