c++ - C++ H文件问题

标签 c++ c header-files

这是我的代码。我不断收到很多错误,但我不确定自己在做什么错。

#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/

相关文章:

c++ - 将函数绑定(bind)到范围以生成迭代函数

c++ - 为什么system_clock time_point不能从duration构造?

c++ - 在 64 位机器上编译 32 位 :/usr/bin/ld: cannot find -l<someLibs>

c - C 中 (void)variable 的用途是什么?

c - 头文件难点

c++ - 给定源文件的 header "corresponding"是否有技术名称?

C++ 在带有右值缓冲区的 ostream 中使用 snprintf,格式是否正确?

c++:内存中静态库的多个拷贝

c - 在堆数组上使用数组初始化符号

c++ - 为什么必须内联定义在类外部(但在头文件中)的类成员函数?