gpt4 book ai didi

C错误: Identifier is undefined

转载 作者:行者123 更新时间:2023-11-30 17:24:49 25 4
gpt4 key购买 nike

我完全不知道为什么会出现这些错误。我的代码是这样的:

类型.h

typedef struct {
int* myInt;
} myType;

class.h

#ifndef myClass
#define myClass

#include "type.h"

void makeMyType( myType& t );
void deleteMyType ( myType& t );

#endif

类.C

#include "type.h"

makeMyType( myType& t ) {
t.myInt = (int*) malloc (sizeof(int));
t.myInt = 0;
}
deleteMyType ( myType& t ) {
free (t);
}

useType.C

#include "type.h"
#include "class.h"

int main {
myType t;
makeMyType (t);
deleteMyType (t);
return 0;
}

然后编译器给我以下内容:

error: identifier "makeMyType" is undefined
error: identifier "deleteMyType" is undefined

什么可能导致此错误?我该如何修复它?

最佳答案

class.c中包含class.h而不是type.h,在useType.c中包含只是class.h

类型.h

typedef struct {
int* myInt;
} myType;

类.h

#ifndef myClass
#define myClass

#include "type.h"

void makeMyType( myType& t );
void deleteMyType ( myType& t );

#endif

类.C

#include "class.h"

makeMyType( myType& t ) {
t.myInt = (int*) malloc (sizeof(int));
t.myInt = 0;
}
deleteMyType ( myType& t ) {
free (t);
}

useType.C

#include "class.h"

int main {
myType t;
makeMyType (t);
deleteMyType (t);
return 0;
}

关于C错误: Identifier <funtion_from_other_header> is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27192088/

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