java typedef struct,'struct ...'没有名为[closed]的成员

本文讨论了在C语言编程中遇到的结构体成员访问错误,包括'structcheck'没有名为'refc'和'valor'的成员的警告。错误源于头文件和源文件中结构体定义不一致,以及格式化输出时的数据类型匹配问题。解决方案包括修正结构体成员名和调整格式化打印的类型匹配。同时,提到了未声明的'strdup'函数及其使用,以及指针类型转换的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

为什么我一直收到这个错误:

struct没有成员[-Wpedantic]'struct check'没有名为'refc'的成员'struct check'没有名为'valor'的成员

等 . 代码如下

#ifndef _ITEM_

#define _ITEM_

#include

#include

#include

#define key (a) (a != NULL ? a->refc : "")

#define less (a,b) (strcmp (a,b)<0)

#define eq(a,b) (strcmp (a,b) == 0)

#define NULLitem NULL

typedef long int* Key;

typedef struct cheque {

int valor

long int refe

long int refb

long int* refc

}*Item;

Item newItem (int valor, long int refe, long int refb, long int* refc);

void deleteItem (Item a);

void visitItem (Item a);

#endif

编辑:

现在我正面临着以下错误,

Item.c:6:36:错误:在'refe'之前预期';',','或')'项目newItem(int valor,long item refe,long item refb,long item * refc)^ Item.c :在函数'visitItem'中:Item.c:32:2:警告:格式'%d'需要类型为'int'的参数,但参数2的类型为'long int'[-Wformat =] printf(“refe:% d \ n“,a-> refe); ^ Item.c:33:2:警告:格式'%d'需要类型为'int'的参数,但参数2的类型为'long int'[-Wformat =] printf(“refb:%d \ n”,a - > REFB);代码如下

item.h

#ifndef _ITEM_

#define _ITEM_

#include

#include

#include

#define key (a) (a != NULL ? a->refc : "")

#define less (a,b) (strcmp (a,b)<0)

#define eq(a,b) (strcmp (a,b) == 0)

#define NULLitem NULL

typedef long int* Key;

typedef struct cheque {

int valor;

long int refe;

long int refb;

long int* refc;

}*Item;

Item newItem (int valor, long int refe, long int refb, long int* refc);

void deleteItem (Item a);

void visitItem (Item a);

#endif

item.c

#include "Item.h"

#include

#include

Item newItem (int valor, long item refe, long item refb, long item* refc)

{

Item x = (Item) malloc (sizeof(struct cheque));

x->valor = valor;

x->refe = refe;

x->refb = refb;

x->refc = strdup(refc);

return x;

}

void deleteItem (Item a)

{

free(a->refc);

free(a);

}

void visitItem (Item a)

{

printf("valor: %d\n", a->valor);

printf("refe: %d\n", a->refe);

printf("refb: %d\n", a->refb);

printf("refc: %ld\n", a->refc);

}

EDIT_v2

Item newItem (int valor, long int refe, long int refb, long int* refc)

printf("valor: %d\n", a->valor);

printf("refe: %ld\n", a->refe);

printf("refb: %ld\n", a->refb);

printf("refc: %p\n", a->refc);

在纠正这些错误后,我收到了以下错误:

Item.c:在函数'newItem'中:Item.c:14:2:warning:函数'strdup'的隐式声明[-Wimplicit-function-declaration] x-> refc = strdup(refc); ^ Item.c:14:10:警告:赋值从整数中生成没有强制转换的指针[默认启用] x-> refc = strdup(refc); Item.c:在函数'visitItem'中:Item.c:34:2:警告:格式'%p'需要类型为'void *'的参数,但参数2的类型为'long int *'[-Wformat =] printf (“refc:%p \ n”,a-> refc);

Edit_ v3

1问题修正纠正:

x->refc = refc;

错误atm:

Item.c:在函数'visitItem'中:Item.c:34:2:警告:格式'%p'需要'void *'类型的参数,但参数2的类型为'long int *'[-Wformat =] printf(“refc:%p \ n”,a-> refc);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值