Can anyone check my memory class and suggest changes or things I may need? I'm writing it so that I don't have to worry about deleting anything everytime I allocate.
#include <iostream>
template<typename T>
class Memory
{
private:
size_t size;
T* data;
public:
explicit Memory(size_t Size) : size(Size), data(new T[Size]){}
~Memory()
{
if (data)
delete[] data;
}
Memory(Memory& Block) : size(Block.size), data(new T[Block.size])
{
//if (data)
//delete[] data;
std::copy(Block.data, Block.data + size, data);
}
/*
Memory(Memory& Block) : size(Block.size)
{
if (data)
delete[] data;
data = new T[Block.size];
std::copy(Block.data, Block.data + size, data);
}
*/
Memory& operator = (Memory& Block)
{
if (this != &Block)
{
delete[] data;
size = Block.size;
data = new T[size];
std::copy(Block.data, Block.data + size, data);
}
return *this;
}
size_t Size() const
{
return size;
}
};