关于嵌套结构的问题 [英] Question about nested structures
本文介绍了关于嵌套结构的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
1。我读了很多教程,我理解嵌套结构的方法,但我无法理解
为什么我们使用嵌套结构?
1. I read many tutorials i understand the method of nested structures but i can not understand
why we use nested structures?
推荐答案
因为成员作为一个简单的变量,结构可以更复杂,例如 struct date :
Because the member of a structure can be more complex as a simlple variable, for example like struct date:
struct Employee
{
char ename[20];
int ssn;
float salary;
struct date
{
int date;
int month;
int year;
}doj;
}emp;
以下C风格:
The following C style:
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;
...将与C ++风格相等:):
...would be "equal" to the C++ style :) :
class CPoint
{
int x, y;
public:
//...
};
class CCircle : public CPoint
{
int r;
public:
//...
};
class CCircleEx
{
CPoint c;
int r;
public:
//...
};
这篇关于关于嵌套结构的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文