Click here to Skip to main content
16,022,542 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
1. I read many tutorials i understand the method of nested structures but i can not understand
why we use nested structures?
Posted

The following C style:
C++
typedef struct {
  int x, y;
} point, * ppoint;

typedef struct {
  point; // a "derivation" :)
  int r;
} circle, * pcircle;

typedef struct {
  point c; // an aggregation :)
  int r;
} circleEx, * pcircleEx;

...would be "equal" to the C++ style :) :
C++
class CPoint
{
  int x, y;

public:
  //...
};

class CCircle : public CPoint
{
  int r;

public:
  //...
};

class CCircleEx
{
  CPoint c;
  int r;

public:
  //...
};
 
Share this answer
 
v2
Comments
Leo Chapiro 7-Mar-13 9:10am    
Good point, actually shoud the question means "Why we use nested structures in C" :)
Eugen Podsypalnikov 7-Mar-13 9:21am    
Very likely... :)
Thank you !
Because the member of a structure can be more complex as a simlple variable, for example like struct date:

C#
struct Employee
{
   char ename[20];
   int ssn;
   float salary;
   struct date
       {
       int date;
       int month;
       int year;
       }doj;
}emp;
 
Share this answer
 
v3

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