gpt4 book ai didi

C 结构指针问题

转载 作者:行者123 更新时间:2023-12-04 05:23:28 25 4
gpt4 key购买 nike

我正在构建一个链表,这是列表项结构:

struct TListItemStruct
{
void* Value;
struct TListItemStruct* NextItem;
struct TListItemStruct* PrevItem;
};
typedef struct TListItemStruct TListItem;
typedef TListItem* PListItem;

我在几个函数中使用它,到目前为止看起来还可以。但是,当我定义以下变量时:
PListItem item;

我收到以下错误:
error C2275: 'PListItem' : illegal use of this type as an expression

为什么?定义指向 struct 的指针类型的变量有什么问题?

编辑:
这是更多的功能。这不起作用
BOOL RemoveItem(PListItem item)
{
// Verify
if (item == NULL)
{
return FALSE;
}
// Get prev and next items
PListItem prev;
prev = item->PrevItem;
//PListItem next = (PListItem)(item->NextItem);
...

但是这有效:
BOOL RemoveItem(PListItem item)
{
PListItem prev;
// Verify
if (item == NULL)
{
return FALSE;
}
// Get prev and next items
prev = item->PrevItem;
//PListItem next = (PListItem)(item->NextItem);
...

我正在使用 VS2012,也许这是一个标准的东西?在函数的开头声明vars?

最佳答案

MSVC 使用 C89,它不支持 C99,因此您需要在函数的开头声明所有变量或编译为 C++。

关于C 结构指针问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13460297/

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