#ifndef _BOXTPTR_HPP_ #define _BOXTPTR_HPP_ #include "Box.hpp" template class Box { T *e; public: Box(); Box(T* e); Box(const Box& b); ~Box(); T* get() const; void set(T* e); template friend std::ostream& operator<<(std::ostream& out, const Box& t); Box& operator=(Box& b); }; template Box::Box() { this->e = nullptr; } template Box::Box(T* e) { this->e = new T; *(this->e) = *e; } template Box::Box(const Box& b) { this->e = new T; *(this->e) = *b.e; } template Box::~Box() { delete this->e; } template T* Box::get() const { T *ce = new T; *ce = *e; return ce; } template void Box::set(T *e) { if(this->e != nullptr) delete this->e; this->e = new T; *(this->e) = *e; } template std::ostream& operator<<(std::ostream& out, const Box& t) { T* ptr = t.get(); out << *ptr; delete ptr; return out; } template Box& Box::operator=(Box& b){ set(b.e); return *this; } #endif