gpt4 book ai didi

c++ - 预定义struct,报错

转载 作者:行者123 更新时间:2023-11-30 04:05:03 27 4
gpt4 key购买 nike

我有三个来源:代码处理.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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com