初心者ではC++です。私は動的オブジェクト配列を作成し、std :: sort()を使ってそれらをソートしたいと思います。しかし、いくつかのエラーが表示され、私は理由を把握できませんでした。助けてくれてありがとう。 エラーは次のように表示されます。iterator_category ':' std :: iterator_traits <_InIt> 'の基本クラスのメンバーではありません
> community\vc\tools\msvc\14.10.25017\include\xutility(988): > error C2794: 'iterator_category': is not a member of any direct or > indirect base class of 'std::iterator_traits<_InIt>' > with > [ > _InIt=Problem > ] \include\algorithm(2915): > note: see reference to function template instantiation 'void > std::_Debug_range<_RanIt>(_InIt,_InIt,std::_Dbfile_t,std::_Dbline_t)' > being compiled > with > [ > _RanIt=Problem, > _InIt=Problem
#include "stdafx.h"
#include "stdlib.h"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
class Problem{
public:
string name;
int t;
int d;
Problem() {}
Problem(string name,int t,int d):name(name),t(t),d(d) {}
~Problem() {}
bool operator<(const Problem &right) const {
if (t == right.t) return d < right.d;
else return t < right.t;
}
};
void FindOrder(int H, int N, int t0, Problem ProblemSet[]);
bool compare(const Problem &left,const Problem &right) {
if (left.t == right.t) return left.d < right.d;
else return left.t < right.t;
}
int main()
{
int H, N, t0;
cin >> H;
while (H >= 0) {
cin >> N >> t0;
//Problem ProblemSet = (Problem)malloc(N * sizeof(struct ProblemNode));
Problem* ProblemSet = new Problem[N];
for (int i = 0;i<N;i++)
cin >> ProblemSet[i].name >> ProblemSet[i].t >> ProblemSet[i].d;
FindOrder(H, N, t0, ProblemSet);
delete[] ProblemSet;
cin >> H;
}
return 0;
}
void FindOrder(int H, int N, int t0, Problem ProblemSet[]) {
int total = t0;
sort(ProblemSet[0], ProblemSet[N-1]);
for (int i = 0;i < N;i++) {
cout << ProblemSet[i].name << ProblemSet[i].t << ProblemSet[i].d << endl;
}
}
あなたのエラーメッセージは、あなたのコードのどの行がこの混乱を引き起こしたかを教えてください。それは何ですか? – NathanOliver
'sort(ProblemSet [0]、ProblemSet [N-1]);'が間違っています。未知のサイズの配列にインデックスを付けることはイテレータを生成しません。あなたはたぶん 'sort(ProblemSet、ProblemSet + N);' – WhiZTiM
を意味しています。エラーメッセージは基本的に "' Product'はイテレータではありません。 Your'eは2つの 'Product'sを' sort'に渡します。 – molbdnilo