C++ - 包含文件太多? & 结构重定义?

标签 c++ tokenize

我目前正在为 XML 编写 token 识别器。我将在 FSA 的基础上这样做。所以我有一个包含以下代码的头文件...

#define MAX_LENGTH    512
#define  MAX_NAME  25

struct token 
{
  char name[MAX_NAME + 1];
  int type;
  unsigned char str[MAX_LENGTH + 1];
 };

 #define TOKEN_TYPES 8

 #define SPACES  0
 #define NEWLINE  1
 #define WORD  2
 #define BEGINTAG  3
 #define ENDTAG  4
 #define EMPTYTAG 5
 #define ERROR 6
 #define ENDFILE 7

有了这个我得到了错误:

error C2011: 'token' : 'struct' type redefinition

我的 gettoken.cpp 文件中还出现了另一个奇怪的错误。我实际实现 FSA 的地方。文件太长无法显示全部内容。但是有了这个我得到了错误...

error C1014: too many include files : depth = 1024

这是该 .cpp 文件的部分代码。我将只包括我的进口商品。

#include  <iostream>
#include  <fstream>
#include  <stdlib.h>
#include  <string>
#include  "Token.h"

using namespace std;

我确信这对我来说通常是愚蠢的。但是请帮帮我!谢谢!

最佳答案

我假设您以某种方式两次包含头文件。你对此有防范吗?每个头文件都应该有这个:

#ifndef TOKEN_H
#define TOKEN_H

[your header file code]

#endif

如果不是这样,请确保您没有在其他地方两次定义 token 。

关于C++ - 包含文件太多? & 结构重定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4103009/

相关文章:

c - 在 C 中标记用户输入(存储在 **arg 中)?

python - 如何在 NLP 中的 TweetTokenizer 步骤中删除标点符号和数字?

c++ - 将字符串标记为字符串 vector

c++ - 递归阶乘函数无法正常工作

c++ - 通过指针访问 char*

c++ - 字符串在 vector 数组中被复制

c++ - 在此聚合类中未调用构造函数

sql - 将列拆分为多行

python - 使用 Python NLTK 对大型 (>70MB) TXT 文件进行标记。串联并写入数据以流式传输错误

C++ 模板和重载下标运算符