Linked Lists
is it possible to have a linked list of structs within structs? something like this
struct Struct1
{
int num1;
};
struct Struct2
{
Struct1 str1;
Struct2 *pnext;
};
Struct2 teststruct;
now how, if possible, would i access num1 using teststruct?
teststruct.str1.num1
or, since you spoke of linked lists
if(pnext != NULL){
teststruct.pnext->str1.num1
}
I am not sure if you can make a declaration of a struct within itself, so you could try
struct Struct2
{
Struct1 str1;
void *pnext;
}
then access with a cast
((Struct2 *)pnext)->str1.num1
[edited by - variant on March 14, 2003 3:47:33 PM]
or, since you spoke of linked lists
if(pnext != NULL){
teststruct.pnext->str1.num1
}
I am not sure if you can make a declaration of a struct within itself, so you could try
struct Struct2
{
Struct1 str1;
void *pnext;
}
then access with a cast
((Struct2 *)pnext)->str1.num1
[edited by - variant on March 14, 2003 3:47:33 PM]
quote:
Original post by variant
I am not sure if you can make a declaration of a struct within itself, so you could try
Don''t worry, you can do that

The pointer was ok as it was...What''s not allowed is this:
struct Struct2 {Struct1 obj1;Struct2 infiniteMemoryUseIsNotPossibleSoCompileError;}
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
You can''t declare a structure with the tag unless you prefix it with the struct keyword.
like this
Thats why we have typedef...
-Will
like this
struct mystruct { int data; struct mystruct* next;}struct mystruct* head;
Thats why we have typedef...
-Will
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement