Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can I define a structure within which there is a variable of type the structure itself? Something like:

C++
struct FOO
{
int iVariable;
FOO variable;
};
Posted
Updated 27-Oct-11 3:47am
v2

1 solution

No.
It means that the size of the structure would have to be the size of the structure plus the size of an int. Which means that the size would change, and so...

You can include a pointer to the same structure, but not the structure itself.
C++
struct FOO
{
int iVariable;
FOO* variable;
};
 
Share this answer
 
Comments
Yuri Vital 27-Oct-11 10:06am    
joseph : it's the basic concept of Linked list !
http://en.wikipedia.org/wiki/Linked_list
Joseph Marzbani 27-Oct-11 10:20am    
I'm just a beginner :-)
Joseph Marzbani 27-Oct-11 10:07am    
Thank you for your reply. Basically I meant the same. That's defining a POINTER to the structure. Thank you ...
OriginalGriff 27-Oct-11 10:19am    
You're welcome!
Albert Holguin 27-Oct-11 10:53am    
+5, easy points.. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900