Skip to content

Instantly share code, notes, and snippets.

@TheRolfFR
Created November 23, 2022 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRolfFR/c1830ebee942bc87c5fd14f6894cefc2 to your computer and use it in GitHub Desktop.
Save TheRolfFR/c1830ebee942bc87c5fd14f6894cefc2 to your computer and use it in GitHub Desktop.
Smart Pointer implementation
template <class Type>
class SmartPointer
{
private:
Type * pointer;
public:
SmartPointer() : pointer(nullptr) {}
SmartPointer(Type * p) : pointer(p) {}
Type * set(Type * p) { pointer = p; return p; }
Type * get() { return pointer; }
void destroy() { if(pointer != nullptr){ delete pointer; pointer = nullptr; } }
~SmartPointer() { destroy(); }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment