Use std::vector<Citizen>
instead of an array and the problem will likely disappear by itself. A standard container like std::vector
manages all memory automatically for you. You will end up with no new
and delete[]
at all in your code.
Just to give you an idea, this is what your Add_citizen
function would then look like:
void TaxRegister::Add_citizen( const string& name, const string& addr )
{
m_People.push_back(Citizen(name, addr));
}
You are already using std::string
instead of char const *
. That's good. Using std::vector
instead of arrays is exactly the same improvement.