我目前正在为 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/