私はこの消去機能を実行してベクターから '2'を削除しようとしたときにエラーのリストを検出しました。私はどこに問題があるのか分かりません。ヘルプは非常に高く評価されます!ベクトル内の特定の値を削除する
STRUCTミン
struct MyInt
{
friend ostream &operator<<(ostream &printout, const MyInt &Qn)
{
printout<< Qn.value << endl;
return printout;
}
int value;
MyInt (int value) : value (value) {}
};
STRUCTのMyStuff
struct MyStuff
{
std::vector<MyInt> values;
MyStuff() : values()
{ }
};
MAIN
int main()
{
MyStuff mystuff1,mystuff2;
for (int x = 0; x < 5; ++x)
{
mystuff2.values.push_back (MyInt (x));
}
vector<MyInt>::iterator VITER;
mystuff2.values.push_back(10);
mystuff2.values.push_back(7);
//error points to the line below
mystuff2.values.erase(std::remove(mystuff2.values.begin(), mystuff2.values.end(), 2), mystuff2.values.end());
return 0;
}
エラーメッセージ
stl_algo.h:関数内で '_OutputIteratorのstd :: remove_copy(_InputInputIterator、_InputIterator、const_Tp &)[with_InputIterator = __gnu_cxx:__ normal_iterator>>、OutputIterator = __ gnu_cxx :: __通常のイテレータ>>、Tpは= INT]'
オペレータのための一致が==」
Erorrメッセージがpartciularラインが ライン1267、1190、327、1263、208、212、216、220、228、232、実質的にstl_algo.hのラインに違反示しました。 、236
「いいえ試合をオペレータのために==」何がそれについて不明ですか? 'myInt'と整数を比較できるように'演算子== '関数を定義する必要があります。 – jrok
@jrok、それは答えになるはずです。それは本当に簡単です。 – chris