User forums > Help
Linked Lists and Typdef Struct
maestroh:
I'm trying to create a linked list, and due to the lack of support of 'typdef struct' I'm having trouble determining how I should code the list.
Here is some sample code which is similar to what I'm trying to do.
--- Code: ---struct node
{
char a;
node *next;
};
typedef struct node *head;
int main()
{
head na;
na = new node;
//na-> //This line doesn't display any members of the node struct.
}
--- End code ---
Are there any workarounds to the typedef struct problem? Or am I just not defining 'node' and 'head' correctly?
Thanks
MortenMacFly:
A search through the forum would have revealed that: ;-)
http://forums.codeblocks.org/index.php?topic=4523.msg35742#msg35742
With regards, Morten.
maestroh:
Hey Morton,
I'm glad you replied. I did find your post, and I was excited when I did. But when I went to implement the code, I realized that the name Flex is ambiguous becuase the name is used for both the struct definition and the type definition. If you change the type definition to something else, your code doesn't work. If you take the typedef out entirely is works the same as if the typedef were left in with the ambiguous definition. Once I realized that I was back at square one.
Any other suggestions?
Thanks
MortenMacFly:
--- Quote from: maestroh on December 14, 2006, 06:26:17 pm ---Any other suggestions?
--- End quote ---
If you insist to name a typedef different than the struct (why?) then unfortunately no, not at the moment.
With regards, Morten.
maestroh:
--- Quote ---If you insist to name a typedef different than the struct (why?)
--- End quote ---
The reason I want to name the typedef different than the struct is to create a type that is a pointer to the struct type.
From my example:
--- Code: ---struct node
{
char a;
node *next;
};
typedef struct node *head;
--- End code ---
'head' is a pointer to the 'node' type. I guess my question is: Is there any way to create a type that's a pointer to the struct?
Thanks again. I appreciate your help Morten.
Navigation
[0] Message Index
[#] Next page
Go to full version