当我将List与pop_back()一起使用时,我最近遇到了一些麻烦。
首先,我将结构定义如下:
struct Pareto{
double PCost;
double PDist;
double DMax,DMin,DAvg,DStd;
Pareto(double pCost, double pDist, double dMax, double dMin, double dAvg, double dStd){
PCost = pCost;
PDist = pDist;
DMax=dMax;
DMin = dMin;
DAvg = dAvg;
DStd= dStd;
}
};
然后我制作了一个Struct列表,如下所示。
list<Pareto> ParetoSet;
奇怪的是,当我使用push_back时没有错误,但是当我使用pop_back时,会发生以下错误。
ParetoSet.pop_back();
错误LNK2019&amp; LNK1120
“public:class std :: list&gt; :: _ Const_iterator&lt; 1&gt;&amp; __thiscall std :: list&gt; :: _ Const_iterator&lt; 1&gt; :: operator - (void)”(?? F?$ _ Const_iterator @ $ 00 @?$ list @ UPareto @@ V?$ allocator @ UPareto @@@ std @@@ std @@ QAEAAV012 @XZ)功能
我该如何解决这个问题?
答案 0 :(得分:0)
无法重现您的问题。 你能跑吗?
#include <iostream>
#include <list>
using namespace std;
struct Pareto{
double PCost;
double PDist;
double DMax,DMin,DAvg,DStd;
Pareto(double pCost, double pDist, double dMax, double dMin, double dAvg, double dStd){
PCost = pCost;
PDist = pDist;
DMax=dMax;
DMin = dMin;
DAvg = dAvg;
DStd= dStd;
}
};
ostream& operator<<(ostream& out, Pareto& p) {
out << "PCost: " << p.PCost << ", PDist: " << p.PDist << ", DMax: " << p.DMax << ", DMin: " << p.DMin << ", DAvg: " << p.DAvg << ", DStd: " << p.DStd;
return out;
}
int main() {
list<Pareto> list;
list.push_back({0, 1, 2, 3, 4, 5});
list.push_back({0, 10, 20, 30, 40, 50});
cout << "Initial size: " << list.size() << endl;
list.pop_back();
cout << "Size after pop_back: " << list.size() << endl;
Pareto p = list.back();
cout << "Left item: " << p;
}