那里。我是C ++的新手,并试图用图算法练习一些东西。我在一个类中定义了两个结构:
#include <vector>
using namespace std;
enum GraphType{undigraph, digraph, undinetwork, dinetwrok};
template <class T>
struct EdgeType
{
T head, tail;
int cost;
EdgeType(T head, T tail, int cost)
{
this->head = head;
this->tail = tail;
this->cost = cost;
}
};
template <class T>
struct Edge
{
T adjvex;
int lowcost;
};
template <class T>
class MGraph
{
private:
int vexnum, edgenum;
GraphType kind;
vector<vector<int> >edges; //二维邻接矩阵
vector<T> vexs; //顶点表
public:
...
void Prim(int v); //Prim算法求最小生成树
void Kruskal(vector<EdgeType<T> > &tree); //Kruskal算法构造最小生成树
int getMiniNum(Edge<T>* edges);
void getGraph(vector<EdgeType<T> > &graph);
};
以下是我的CPP文件中的错误:
template <class T>
void MGraph<T>::Kruskal(vector<EdgeType<T> > &tree)
{
int i;
vector<EdgeType<T> > graph;
getGraph(graph);
tree.resize(vexnum-1);
...
}
template<class T>
void MGraph<T>::getGraph(vector<EdgeType<T> > &graph)
{
graph.resize(edgenum);
int min = 0;
int k = 0;
int i,j;
for(i = 0; i < vexnum; i++)
{
for(j = 0; j < i; j++)
{
if(edges[j][i] < INFINITY && i != j)
{
char s1 = graph[k].head = getVexValue(j);
char s2 = graph[k].tail = getVexValue(i);
int p = graph[k].cost = edges[j][i];
k++;
}
}
}
EdgeType<T> e;
for(i = 1; i < edgenum; i++)
{
for(j = edgenum-1; j >= i; j--)
{
if(graph[j].cost < graph[j-1].cost)
{
e = graph[j-1];
graph[j-1] = graph[j];
graph[j] = e;
e = graph[j];
}
}
}
}
C:\Windows\system32\cmd.exe /C "C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'D:/test/test/test'
C:/TDM-GCC-64/bin/g++.exe -c "D:/test/test/test/main.cpp" -g -O0 -Wall -o ./Debug/main.cpp.o -I. -I.
D:/test/test/test/MGraph.cpp: In instantiation of 'void MGraph<T>::Kruskal(std::vector<EdgeType<T> >&) [with T = char]':
D:/test/test/test/main.cpp:57:17: required from here
D:/test/test/test/MGraph.cpp:368:2: error: no matching function for call to 'EdgeType<char>::EdgeType()'
tree.resize(vexnum-1);
^
D:/test/test/test/MGraph.cpp: In instantiation of 'void MGraph<T>::getGraph(std::vector<EdgeType<T> >&) [with T = char]':
D:/test/test/test/MGraph.cpp:367:16: required from 'void MGraph<T>::Kruskal(std::vector<EdgeType<T> >&) [with T = char]'
D:/test/test/test/main.cpp:57:17: required from here
D:/test/test/test/MGraph.cpp:415:2: error: no matching function for call to 'EdgeType<char>::EdgeType()'
graph.resize(edgenum);
^
D:/test/test/test/MGraph.cpp:432:14: error: no matching function for call to 'EdgeType<char>::EdgeType()'
EdgeType<T> e;
^
mingw32-make.exe[1]: *** [Debug/main.cpp.o] Error 1
test.mk:93: recipe for target 'Debug/main.cpp.o' failed
mingw32-make.exe[1]: Leaving directory 'D:/test/test/test'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
7 errors, 29 warnings
我不知道如何解决这个问题,有人请帮助我吗?非常感谢!