1.定义:
struct:用来定义一个结构体;
typedef:用来类型换名;
typedef struct表示将定义后的结构体定义成想要的类型名;
2.举例:
(1)代码:
#include<iostream>
using namespace std;
typedef int Int32;
struct HuffmanCode {
char c;
Int32 num;
};
typedef HuffmanCode Code;
typedef struct student {
string name;
long Id;
}stu;
typedef struct teacher {
string name;
long Id;
};
void main()
{
Code H = { 'A',5 };
HuffmanCode C = { 'B',2 };
cout << H.c << "\t" << H.num << endl;
cout << C.c << "\t" << C.num << endl;
C = H;
cout << C.c << "\t" << C.num << endl;
stu A = { "CSS",20152000 };
student B = { "CYR",20150000 };
cout << A.name << "\t" << A.Id << endl;
cout << B.name << "\t" << B.Id << endl;
A = B;
cout << A.name << "\t" << A.Id << endl;
teacher T = { "ZHX",14234353 };
cout << T.name << "\t" << T.Id << endl;
}
(2)测试截图:
