【发布时间】:2014-05-05 22:16:27
【问题描述】:
我有三个来源: codeproc.h
typedef enum {typeBool, typeVarDeclaration, typeFuncDeclaration } nodeEnum;
typedef struct varDeclarationNodeType{
char *varName; /* Var Name */
int defaultType; /* default value type*/
int defaultValue; /* default value*/
int ndim; /* number of dimensions */
int *dim; /* dimensions (expandable) */
} varDeclarationNodeType;
typedef struct {
char *funcName;
std::vector<char *> *args; /* arguments (expandable) */
} funcDeclarationNodeType;
typedef struct {
bool value;
} boolNodeType;
typedef struct nodeTypeTag {
nodeEnum type; /* type of node */
union {
boolNodeType boolVal; /* bools */
varDeclarationNodeType varDeclaration; /*var declarations*/
funcDeclarationNodeType funcDeclaration;
};
} nodeType;
codeproc.cpp
#include "codeproc.h"
#include "codecontext.h"
...
codecontext.h
#include "codeproc.h"
class Function{
public:
Function();
~Function();
map<string, Value*> locals; //local variables
map<string, Value*> args; //arguments
int numOfArgs; //number of arguments
nodeType *entryPoint; //first statement in function
Value *lastCallResult; //variable that contain result from last call
};
错误:
codeproc.h 错误:“varDeclarationNodeType”之前的声明为“typedef struct varDeclarationNodeType varDeclarationNodeType”
就像那样。 这种情况下如何预定义struct?
【问题讨论】:
-
codecontext 包含codeproc,可以避免直接包含在cpp文件中
-
您需要包含警卫(或确保 100% 不会多次包含同一个文件)
-
谢谢,我在一个标题中错过了一个包含保护。