set_union (algorithm.cpp に含まれる) と STL ライブラリのセットを使用しています。
私のセットは、operator= をオーバーロードしたカスタム クラス Vertex のオブジェクトを保持します。
頂点クラスは次のとおりです。
class Vertex {
public:
City city;
bool wasVisited;
Vertex() {};
Vertex(City c) {city = c; wasVisited = false;}
double getWeightToVertex(Vertex v) {return city.getWeightWith(v.city);}
Vertex& operator=(const Vertex&v) {
if(this == &v)
return *this;
city = v.city;
return *this;
}
};
問題は、別のクラスのメソッドに含まれる次の行にあります。
for(int i=0; i<nEdges; i++) {
Edge e = edges[i];
Vertex start = vertexList[e.start];
Vertex end = vertexList[e.end];
if(sets[e.start].find(vertexList[e.end]) == sets[e.start].end()) { // The two vertices do not belong to the same set
//Add the edge to our MST
MST[nValidEdges] = e;
nValidEdges++;
//Get the union of vertex sets and insert it
//in the corresponding place in the dynamic array
set<Vertex> unionSet;
set_union(sets[e.start].begin(), sets[e.start].end(), sets[e.end].begin(), sets[e.end].end(), unionSet.begin());
sets[e.start] = unionSet;
}
}
そのコードは、algorithm.cpp でコンパイル エラーを生成します。具体的には、set_union のコードで、'InputIterator' 型の 2 つのオブジェクトに対して実行可能なオーバーロードされた operator= がないことを示しています。
コンパイラ エラーの場所は次のとおりです。
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__first, ++__result)
*__result = *__first; //Error Here: No Viable Overloaded '='
return __result;
}
ここで何が欠けていますか?