Created
November 23, 2022 08:50
-
-
Save TheRolfFR/c1830ebee942bc87c5fd14f6894cefc2 to your computer and use it in GitHub Desktop.
Smart Pointer implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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