这是我的代码。我不断收到很多错误,但我不确定自己在做什么错。
#include <iostream>
#ifndef PROJ1_H
#define PROJ1_H
using namespace std;
class Graph{
public:
void InitializeGraph(int graph[][MAX_VERTICES], int size);
bool RemoveEdge(int graph[][MAX_VERTICES], int size, int u, int v);
bool CreateEdge(int graph[][MAX_VERTICES], int size, int u, int v);
bool IsEdge(int graph[][MAX_VERTICES], int size, int u, int v);
bool IsConnected(int graph[][MAX_VERTICES], int size);
private:
};
#endif
当我编译它时,这些是我得到的错误
proj1.h:11:错误:未在此范围内声明“ MAX_VERTICES”
proj1.h:11:错误:预期在“,”令牌之前的“)”
proj1.h:11:错误:“ int”之前应有预期的unqualified-id
proj1.h:12:错误:未在此范围内声明“ MAX_VERTICES”
proj1.h:12:错误:预期在“,”令牌之前的“)”
proj1.h:12:错误:“ int”之前的预期不合格ID
proj1.h:13:错误:未在此范围内声明“ MAX_VERTICES”
proj1.h:13:错误:预期在“,”令牌之前的“)”
proj1.h:13:错误:“ int”之前的预期unqualified-id
proj1.h:14:错误:在此范围内未声明“ MAX_VERTICES”
proj1.h:14:错误:预期在“,”令牌之前的“)”
proj1.h:14:错误:“ int”之前的预期unqualified-id
proj1.h:15:错误:在此范围内未声明“ MAX_VERTICES”
proj1.h:15:错误:预期在“,”令牌之前的“)”
proj1.h:15:错误:“ int”之前应有不合格ID
最佳答案
您正在使用MAX_VERTICES
,但未定义也未声明。您可以使用以下方法解决错误:
// Use a value that makes sense for your application
#define MAX_VERTICES 1000
要么
const int MAX_VERTICES = 1000;
由于您使用的是C ++,因此请选择第二种方法。
关于c++ - C++ H文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28616798/