I got a template class Atlas that will store objects of Animal class and derived classes of Animal; here's the code:
#include <iostream>
#include <assert.h>
#include <list>
using namespace std;
class Animal {
protected:
    std::string m_name;
    Animal (std::string name): m_name {name} {}
public:
    virtual std::string regn() const { return "???"; }
    virtual ~Animal(){
    cout << "Destructor animal"<<'\n';}
};
class Nevertebrate : public Animal{
public:
    virtual std::string regn() const { return "nevertebrate";}
    virtual ~Nevertebrate();
};
class Vertebrate: public Animal {
protected:
  /*  std::string m_name;
    Vertebrate (std::string name)
        :m_name {name} {} */
        Vertebrate (std::string name)
            : Animal {name} {}
public:
    virtual std::string regn() const { return "vertebrate";}
    virtual ~Vertebrate(){
    cout<<"Destructor vertebrate"<<'\n';};
};
class bird: public Vertebrate {
public:
    bird(std::string name)
        : Vertebrate{ name }{}
    void set_name (std::string nume){
    m_name = nume;}
    std::string get_name(){
    return m_name;}
    virtual std::string regn() const {return "pasare";}
    virtual ~bird (){
    cout << "destructor bird"<<'\n';}
 };
template <class T>
class Atlas
{
private:
    int m_length{};
    T* m_data{};
public:
    void SetLength(int j);
    Atlas(int length)
    {
        assert(length > 0);
        m_data = new T[length]{};
        m_length = length;
    }
    Atlas(const Atlas&) = delete;
    Atlas& operator=(const Atlas&) = delete;
    ~Atlas()
    {
        delete[] m_data;
    }
    void erase()
    {
        delete[] m_data;
        m_data = nullptr;
        m_length = 0;
    }
    T& operator[](int index)
    {
        assert(index >= 0 && index < m_length);
        return m_data[index];
    }
    int getLength() const;
};
template <class T>
int Atlas<T>::getLength() const  
{
  return m_length;
}
template <class T>
void Atlas<T>::SetLength(int j){m_length = j;
}
int main()
{
   Atlas<Bird> AtlasBird(10);
   Bird b;
   AtlasBird.SetLength(11);
   AtlasBird[10] = b      --- it gets a memoryleak from here.
    return 0;
}
I want to overload the += operator so that i can insert a new object into my Atlas, (e.g. AtlasAnimal).
I tried with the SetLength function to increase the length, (e.g. AtlasAnimal.SetLength(11)) but when i try to assign AtlasAnimal[10] an object (e.g. Bird b) it drops a memory leak.
I'm sorry if there was a similar question answered, but i couldn't find anything that helps
