Подходящий конструктор копирования

219
26 июня 2018, 22:40

Есть класс Son который наследует класс CARD, который в свою очередь наследует класс MARSH. Когда я пишу к примеру cout << (Son)So; Пишет что нет подходящего конструктора копирования, что с моим конструктором не так?

Son(Son &z) :CARD(z)
    {
        n = z.n;
        nd = z.nd;
        na = z.na;
        ntl = z.ntl;
        if (z.card != NULL)
        {
            CARD *t5 = new CARD[z.n];
            if (t5 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < n; i++)
                t5[i] = z.card[i];
            card = t5;
        }
        else
            card = NULL;
        if (z.dep != NULL)
        {
            COUNTOFTRAIN *t1 = new COUNTOFTRAIN[z.nd];
            if (t1 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < nd; i++)
                t1[i] = z.dep[i];
            dep = t1;
        }
        else
            dep = NULL;
        if (z.arr != NULL)
        {
            MARSH *t2 = new MARSH[z.na];
            if (t2 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < na; i++)
                t2[i] = z.arr[i];
            arr = t2;
        }
        else
            arr = NULL;
        if (z.tr != NULL)
        {
            traintrain *t3 = new traintrain[z.ntl];
            if (t3 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < ntl; i++)
                t3[i] = z.tr[i];
            tr = t3;
        }
        else
            tr = NULL;
    }

Класс 1:

class MARSH 
{
public:
    string pointofdeparture;
    string arrivalpoint;
    TIME time;
    int trainnumber;
    MARSH() 
    {
        pointofdeparture = "";
        arrivalpoint = "";
        time.hours = NULL;
        time.minutes = NULL;
        trainnumber = NULL;
    }
    MARSH(MARSH &z)
    {
        pointofdeparture = z.pointofdeparture;
        arrivalpoint = z.arrivalpoint;
        time.hours = z.time.hours;
        time.minutes = z.time.minutes;
        trainnumber = z.trainnumber;
    }
};

Класс 2:

class CARD:public MARSH
{
public:
    MARSH pole;
    string surname;
    string init;
    string type;
    double cost;
    CARD() :MARSH()
    {
        surname = "";
        init = "";
        type = "";
        cost = 0;
    }
    CARD(CARD &z) :MARSH(z)
    {
        surname = z.surname;
        init = z.init;
        type = z.type;
        cost = z.cost;
    }

Класс 3:

class Son :public CARD
{
protected:
    CARD *card;
    int n;
    COUNTOFTRAIN *dep;
    int nd;
    MARSH *arr;
    int na;
    traintrain *tr;
    int ntl;
public:
Son():CARD(), card(NULL), n(0), dep(NULL), nd(0), arr(NULL), na(0), tr(NULL), ntl(0) {}
    ~Son() 
    {
        if (card != NULL) delete[] card;
        if (dep != NULL) delete[] dep;
        if (arr != NULL) delete[] arr;
        if (tr != NULL) delete[] tr;
    }
    Son(Son &z) :CARD(z)
    {
        n = z.n;
        nd = z.nd;
        na = z.na;
        ntl = z.ntl;
        if (z.card != NULL)
        {
            CARD *t5 = new CARD[z.n];
            if (t5 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < n; i++)
                t5[i] = z.card[i];
            card = t5;
        }
        else
            card = NULL;
        if (z.dep != NULL)
        {
            COUNTOFTRAIN *t1 = new COUNTOFTRAIN[z.nd];
            if (t1 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < nd; i++)
                t1[i] = z.dep[i];
            dep = t1;
        }
        else
            dep = NULL;
        if (z.arr != NULL)
        {
            MARSH *t2 = new MARSH[z.na];
            if (t2 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < na; i++)
                t2[i] = z.arr[i];
            arr = t2;
        }
        else
            arr = NULL;
        if (z.tr != NULL)
        {
            traintrain *t3 = new traintrain[z.ntl];
            if (t3 == NULL)
            {
                exit(1);
            }
            for (int i = 0; i < ntl; i++)
                t3[i] = z.tr[i];
            tr = t3;
        }
        else
            tr = NULL;
    }
READ ALSO
Преобразование String в Integer C++

Преобразование String в Integer C++

Читал другие темы с этим вопросом, но у меня не получается перевестиПрограмма работает, но вот выводит неправильно

350
Перебор всех возможных сумм массива с++

Перебор всех возможных сумм массива с++

Помогите с алгоритмом для программы

208
Некорректное чтение данных из файла

Некорректное чтение данных из файла

Ввожу и считываю данные этим кодом

222
Правка кода поиска мостов в графе

Правка кода поиска мостов в графе

Написал граф через классы на списку смежностиПомогите написать корректный алгоритм поиска мостов

195