[英]error: definition of implicitly declared copy constructor
我正在解决目前正在研究的Qt C ++项目问题。 这是我要介绍的一个新部分,我发现它有点令人困惑。 我创建了一些由Stock,Bond和Savings类继承的类Asset。 这一切都没问题。 然后我创建了一个名为AssetList的类,它派生了QList,这个类是我发现问题的地方。
这是我到目前为止的代码。
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;
}
我目前得到的错误是编译错误: error: definition of implicitly declared copy constructor
我不太清楚这意味着什么,我一直在谷歌搜索并查看教科书并没有找到太多。 任何人都可以帮助我或让我正确的方向来解决这个问题吗?
提前致谢!
您定义了一个复制构造函数:
AssetList::AssetList(const AssetList&) : QList<Asset*>(){}
但是你没有在AssetList
类中声明它。
你需要添加它:
class AssetList : public QList<Asset*>
{
public:
AssetList(){}
~AssetList();
AssetList(const AssetList&); // Declaring the copy-constructor
...
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.