Работя с set_union (включен в algorithm.cpp) и набори в STL библиотеката.
Моите комплекти съдържат обекти от персонализиран клас Vertex, в който съм претоварил 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, където се посочва, че няма жизнеспособен претоварен operator= за два обекта от тип „InputIterator“.
Ето местоположението на грешката на компилатора:
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;
}
Какво ми липсва тук?
Vertex
, но изхвърляте показалеца. Тогава всъщност не изпълнявате никаква задача. Операторът за присвояване присвоява къмthis
, след което връща*this
. - person Some programmer dude   schedule 02.12.2013