Error: defining an implicitly declared copy constructor

I'm having problems with the Qt C ++ project I'm working on right now. This is a new section that I am covering, and I find it a bit confusing. I have created several Asset classes that are inherited by the Stock, Bond, and Savings classes. Everything was OK. Then I created a class called AssetList that got a QList, this class where I found the problem.

Here is the code I have.

AssetList.h

#ifndef ASSET_LIST_H
#define ASSET_LIST_H

#include "Asset.h"
#include <QString>

class AssetList : public QList<Asset*>
{
public:
    AssetList(){}
    ~AssetList();
    bool addAsset(Asset*);
    Asset* findAsset(QString);
    double totalValue(QString);
};

#endif

AssetList.cpp

#include "AssetList.h"

AssetList::AssetList(const AssetList&) : QList<Asset*>(){}
AssetList::~AssetList()
{
    qDeleteAll(*this);
    clear();
}

bool AssetList::addAsset(Asset* a)
{
    QString desc = a->getDescription();
    Asset* duplicate = findAsset(desc);

    if(duplicate == 0)
    {
        append(a);
        return true;
    }
    else
    {
        delete duplicate;
        return false;
    }
}

Asset* AssetList::findAsset(QString desc)
{
    for(int i = 0 ; i < size() ; i++)
    {
        if(at(i)->getDescription() == desc)
        {
            return at(i);
        }
    }

    return 0;
}

double AssetList::totalValue(QString type)
{
    double sum = 0;

    for(int i = 0 ; i < size() ; i++)
    {
        if(at(i)->getType() == type)
        {
            sum += at(i)->value();
        }
    }

    return sum;
}

The error that I am getting at the moment is a compilation error: error: definition of implicitly declared copy constructorI am not quite sure what this means, I looked for searches in the tutorial and did not find much. Can someone help me or put me in the right direction to figure this out?

Thanks in advance!

+4
1

:

AssetList::AssetList(const AssetList&) : QList<Asset*>(){}

AssetList.

:

class AssetList : public QList<Asset*>
{
public:
    AssetList(){}
    ~AssetList();
    AssetList(const AssetList&);  // Declaring the copy-constructor

    ...
};
+10

Source: https://habr.com/ru/post/1534244/


All Articles