#include <iostream>
using namespace std;
typedef int vertex;
enum vertexstate { white, gray, black };
class graph
{
private:
bool**adjacencymatrix;
int vertexcount;
public:
graph(int vertexcount);
~graph();
void addedge(int i, int j);
void removeedge(int i, int j);
bool isedge(int i, int j);
void display();
void Dfs();
void runDfs(int u, vertexstate state[]);
};
graph::graph(char filename[], int vertexcount) //error is here
{
this->vertexcount = vertexcount;
adjacencymatrix = new bool*[vertexcount];
for (int i = 0; i<vertexcount; i++)
{
adjacencymatrix[i] = new bool[vertexcount];
for (int j = 0; j<vertexcount; j++)
adjacencymatrix[i][j] = false;
}
答案 0 :(得分:1)
除了您的代码示例不完整而且您并未真正制定问题....
您的构造函数定义为graph(int vertexcount);
但您的实现使用了不同的参数:graph(char filename[], int vertexcount)
。
根据您的目标,您有两种可能性:
1)您可以将班级中的定义更改为graph(char filename[], int vertexcount)
2)您可以将实施更改为:#
graph::graph(int vertexcount)
{
this->vertexcount = vertexcount;
adjacencymatrix = new bool*[vertexcount];
for (int i = 0; i<vertexcount; i++)
{
adjacencymatrix[i] = new bool[vertexcount];
for (int j = 0; j<vertexcount; j++)
adjacencymatrix[i][j] = false;
}
}
如果您需要文件名:我建议您使用const std::string&
作为参数类型 - 或者至少const char*
...