I’m constructing a linked-list, and this is the list item Struct:
struct TListItemStruct
{
void* Value;
struct TListItemStruct* NextItem;
struct TListItemStruct* PrevItem;
};
typedef struct TListItemStruct TListItem;
typedef TListItem* PListItem;
I use this in several function and it looks ok so far. However when I define the following variable:
PListItem item;
I get the following error:
error C2275: 'PListItem' : illegal use of this type as an expression
Why is that? What’s wrong with defining a variable of type pointer to struct?
EDITS:
This is more of the function. This doesn’t work
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);
...
However this works:
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);
...
I’m using VS2012, maybe it’s a standard thing? to declare vars in the beginning of the function?
MSVC uses C89, it does not support C99, so you need to either declare all variables at the beginning of your function or compile as C++.