스터디/C++
[ C++ ] 스마트 포인터의 템플릿화
by 알 수 없는 사용자
2019. 11. 30.
#ifndef __SMART_POINTER_TEMPLATE_H_
#define __SMART_POINTER_TEMPLATE_H_
#include <iostream>
#include <cstring>
using namespace std;
template <typename T>
class Smart_Pointer
{
private:
T * ptr;
public:
Smart_Pointer(T* _ptr);
T& operator*() const;
T operator->() const;
~Smart_Pointer();
};
template <typename T>
Smart_Pointer<T>::Smart_Pointer(T* _ptr) : ptr(_ptr)
{ }
template <typename T>
T& Smart_Pointer<T>::operator*() const
{
return *ptr;
}
template <typename T>
T Smart_Pointer<T>::operator->() const
{
return ptr;
}
template <typename T>
Smart_Pointer<T>::~Smart_Pointer()
{
delete ptr;
}
#endif