C++ - Too Many Include Files? & Struct Redefinition?
I am currently writing a token recognizer for XML. I am going along the basis of FSA's to do so. So I have a Header file that has the following code...
#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
With this I am getting the error:
error C2011: 'token' : 'struct' type redefinition
I am also getting another strange error in my gettoken.cpp
file. Where I actually implement the FSA. The File is far to long to display the entire contents. But with this I am getting the error...
error C1014: too many include files : depth = 1024
And here is part of the code for that .cpp file. I will only include开发者_如何学JAVA my imports in this.
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include "Token.h"
using namespace std;
I am sure it is something silly as it usually is for me. But please help me out! Thanks!
I assume you're somehow including your header file twice. Do you have a guard against that? Every header file should have this:
#ifndef TOKEN_H
#define TOKEN_H
[your header file code]
#endif
If that's not it, make sure you're not defining token twice somewhere else.
You are probably missing the include guards and getting into include file recursion.
Add this line to every header file:
#pragma once
精彩评论