我在这里遇到一些问题。我创建了两个向量的矩阵,但是findVertex方法存在问题。
namespace GraphNameSpace
{
template <class T>
class Graph
{
public:
Graph<T>();
void createMatix();
void insertVertex(T Vertex);
int findVertex(T Vertex) const;
private:
vector<vector<int> > matrix;
vector<T> objectsVert;
};
}
template <class T>
void GraphNameSpace::Graph<T>::insertEdge(T fromVertex, T toVertex, int weight=1)
{
if(dir == UNDIRECTED)
{
matrix[findVertex(toVertex)][findVertex(fromVertex)] = weight;
matrix[findVertex(fromVertex)][findVertex(toVertex)] = weight;
}
else
matrix[findVertex(fromVertex)][findVertex(toVertex)] = weight;
template <class T>
int GraphNameSpace::Graph<T>::findVertex(T Vertex) const
{
for(typename vector<T>::iterator it = objectsVert.begin(); it < objectsVert.end(); it++)
{
if(*it == Vertex)
{
return it - objectsVert.begin();
}
}
return 0;
}
***********************在主要********************** ***
int main()
{
Graph<char> Graph3(DIRECTED,WEIGHTED);
char A = 'A';
Graph3.insertVertex(A);
Graph3.insertEdge(A,B,5);
}
问题似乎源于每当使用char时,因为它给了我这个错误:
从'std :: vector&gt; :: const_iterator转换{aka __gnu_cxx :: __ normal_iterator&gt; &gt;}'到非标量类型'std :: vector&gt; :: iterator {aka __gnu_cxx :: __ normal_iterator&gt; &gt;}'要求