主要记录 struct 和 typedef struct的笔记
# include <iostream>
using namespace std;
struct Student
{
int age;
}stu1;
int main()
{
stu1.age = 25;
cout << stu1.age << endl;
system("pause");
}
# include <iostream>
using namespace std;
typedef struct Student
{
int age;
}stu2;
int main()
{
stu2 L;
L.age = 25;
cout << L.age << endl;
system("pause");
}
使用时可以直接访问stu1.a
但是stu2则必须先 stu2 s2;
结构体和类的区别
参考博文
结构体 构造函数的实现
# include <iostream>
using namespace std;
typedef struct Student
{
Student()
{
age = 0;
high = 0;
};
Student(int age1, double high1)
{
age = age1;
high = high1;
}
int age;
double high;
}stu1;
int main()
{
stu1 L;
cout << L.high << endl;
system("pause");
}