Can a structure be used in itself?

November 22, 2010 at 21:46:13
Specs: Windows XP, Dual core/ 2GB
struct structure1
{
datatype member1;
struct structure1 member2;
};

See More: Can a structure be used in itself?

Report •


#1
November 22, 2010 at 23:38:11
No, you can’t use a structure inside itself. Compiler won’t allow you to do that.
Instead you can use a pointer to the structure inside itself.
Like this:
………………………………………………………………………………………………………………………………
struct structure1
{
datatype member1;
structure1* member2;
}
……………………………………………………………………………………………………………………………………..
struct structure1 st;
……………………………………………………………………………………………………………………………………...
And when you need another structure which you want inside of that structure, you can assign a structure to that pointer.
Like this:
…………………………………………………………………………………………………………………………………………..
st.member = new strutcure1;
………………………………………………………………………………………………………………………………………………
If you have difficulty understanding pointers, you can ask here or you can PM me.
I apologize for grammar and spellings.
……………………………………………………………………………………………………………………………………………………….
_Adnan_


Report •

#2
November 23, 2010 at 04:20:20
Thank u......

Report •

Related Solutions


Ask Question