作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有三个来源:代码处理.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;
代码处理.cpp
#include "codeproc.h"
#include "codecontext.h"
...
代码上下文.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 error: 'varDeclarationNodeType' has a previous declaration as 'typedef struct varDeclarationNodeType varDeclarationNodeType'
就这样。这种情况如何预定义struct?
最佳答案
这部分
typedef struct varDeclarationNodeType{
...
} varDeclarationNodeType;
应该是这样的
typedef struct{
...
} varDeclarationNodeType;
并且您应该在头文件中使用头文件保护或#pragma once
。
关于c++ - 预定义struct,报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23482834/
我是一名优秀的程序员,十分优秀!