代码之家  ›  专栏  ›  技术社区  ›  Johnrad

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

  •  0
  • Johnrad  · 技术社区  · 15 年前

    我目前正在为XML编写令牌识别器。我是按照金融服务管理局的规定来做的。所以我有一个头文件,它有以下代码…

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

    我相信这是一件很愚蠢的事情,因为它通常对我来说。但请帮帮我!谢谢!

    3 回复  |  直到 15 年前
        1
  •  3
  •   EboMike    15 年前

    #ifndef TOKEN_H
    #define TOKEN_H
    
    [your header file code]
    
    #endif
    

        2
  •  1
  •   Nikolai Fetissov    15 年前
        3
  •  1
  •   Blindy    15 年前

    #pragma once