1 //LineTable
2 //先是联合体union,,后是结构体,复合型数据类型的一种自定义类型
3
4
5 //内存分配,按整分配。和CPU相关,数据总线
6 //结构体中内存的分配
7 /*
8 内存空洞大,更容易中病毒
9
10 char a[4] = "xyw";
11
12 char b = 'x';
13 char c = 'y';
14 char d = 'w';
15
16
17 内存分配, 有效字节
18 */
19 /*
20
21 特点一
22
23
24 如果定义结构体:
25 int a;
26 char b;
27 int c;
28 char d;
29
30 按照单一型数据类型进行查找 16byte
31
32
33 int a;
34 char b; //合并 12byte
35 char c;
36 int d;
37
38 按大到小或者按小到大;
39 int a;
40 int b;
41 char c;
42 char d;
43 */
44
45 //特点二
46 /*
47
48 结构体有等值运算
49 返回多个值,封到结构体。引用,指针
50 */
51
52
53 /*
54 传参,传地址;
55 省内存,牺牲效率。
56 递归,开辟栈区,浪费了内存。
57 拷贝构造函数。
58 取引用。
59 */
60
61 #include <iostream>
62
63 using namespace std;
64
65
66
67 #define MAX 3
68
69 //_DATA_使用手册,开发手册
70 //开发,,,写函数(封装函数) 调用函数
71 //设计的时候,扩展
72 //代码的封装(函数封装),数据的封装
73 //函数指针,扩展性。
74 //
75
76 /*
77 //函数指针 返回值,参数,参数类型
78 int Add(int a, int b)
79 {
80 int c = a+b;
81 return c;
82 }
83
84 int Sub(int Add(int , int ), int a, int b)
85 {
86
87 }
88 */
89 typedef struct _DATA_
90 {
91 int iAge;
92 char szName[20];
93 }Data,*pData;
94
95 typedef struct _LINETABLE_
96 {
97 // Data DataTemp;
98 //(匈牙利)Lp 长整型指针命名 char(影响计算机执行效率。)dw wchar(16位) wuchar Long dword
99
100 pData pDataTemp;
101
102 int iMax;
103 int iSize;
104 }LineTable, *LineTable;
105
106
107 //匈牙利命名法
108 class CLineTable
109 {
110 public:
111
112
113
114 protected:
115
116 private:
117
118
119 };
120
121 bool CLineTable::InitLineTable(LineTable& LineTableTemp)
122 {
123 LineTableTemp.iMax = MAX;
124 LineTableTemp.pDataTemp = new Data[LineTable.iMax];
125
126 if(LineTableTemp.pDataTemp == NULL)
127 {
128 return false;
129 }
130 else
131 {
132 memset(LineTableTemp.pDataTemp,0,sizeof(Data)*LineTable.iMax);
133
134 LineTableTemp.iSize = 0;
135 }
136 }
137
138 //access
139 //query
140
141
142 int main()
143 {
144 LineTable LineTableTemp = {0};
145
146
147 return 0;
148 }
149 /*
150
151 //函数指针
152 #include <iostream>
153
154 using namespace std;
155
156
157 int Add(int a,int b);
158
159
160 int Sub(int Add(int,int),int a,int b);
161
162
163 void main()
164 {
165
166
167
168 /* char* p = (char*)0x12ff3d;
169 char a[4] = "xyz";
170
171 *p = 'A';
172
173 char b = 'x';
174 char c = 'y';
175 char d = 'z';*/
176
177
178 cout<<Sub(Add,1,2)<<endl;
179
180
181
182 }
183
184
185 int Add(int a,int b)
186 {
187 int c = a+b;
188
189 return c;
190 }
191
192
193 int Sub(int Add(int,int),int a,int b)
194 {
195
196
197 return Add(a,b);
198
199 }
200
201 */