オーバーロードされた< <演算子関数を実装しようとするといくつかの問題が発生していましたが、これは自分のクラスの1つであるstd :: list 。クラスは次のようになります。<<演算子をオーバーロードしてstd :: listを出力する
class NURBScurve {
vector<double> knotVector;
int curveOrder;
list<Point> points;
public:
/* some member functions */
friend ostream& operator<< (ostream& out, const NURBScurve& curve);
};
私が興味を持って主要メンバ変数は、「ポイント」のリストである - これは、関連するメンバ関数と一緒点の座標を格納し、私が作成した別のクラスです。私がしようとすると、オーバーロード< <オペレータの機能を実装する場合:
ostream& operator<<(ostream &out, const NURBScurve &curve)
{
out << "Control points: " << endl;
list<Point>::iterator it;
for (it = curve.points.begin(); it != curve.points.end(); it++)
out << *it;
out << endl;
return out;
}
私は問題を取得するために開始します。 エラー:具体的には、私は次のエラーを取得
no match for ‘operator=’ in ‘it = curve->NURBScurve::points. std::list<_Tp, _Alloc>::begin [with _Tp = Point, _Alloc = std::allocator<Point>]()’
/usr/include/c++/4.2.1/bits/stl_list.h:113: note: candidates are: std::_List_iterator<Point>& std::_List_iterator<Point>::operator=(const std::_List_iterator<Point>&)
を私はここに困惑少しだけど、私はそれは私が使用していますリスト反復子とは何かを持っていると信じています。私はcurve.points.begin()の表記にもあまり自信がない。
誰かが問題に少しでも光を当てることができれば、私はそれを感謝します。私はあまりにも長い間問題を見つめているところです!
あなたは[プリティプリンタ](HTTP与えることができる:/を/stackoverflow.com/questions/4850473/pretty-print-c-stl-containers)試して:-) –