c++ 结构体-struct
结构体,类似于数据结构的实现体,其数据访问控制权限是public
C中格式
c中结构体不可以包含函数
//两种方法等价
//定义
typedef struct Student
{
int age;
string name;
} S;
struct Student
{
int age;
string name;
}
typedef struct Student S;
int main() {
struct Student me; // 或者 S me;
return 0;
}
C++中格式
注意:在C++中,结构体可以包含函数,当定义了与结构体同名的函数Student,此时Student只是代表函数
struct Student
{
int age;
string name;
} ;
struct Student
{
int age;
string name;
} stu;
typedef struct Student
{
int age;
string name;
} stu1;
//stu是结构体变量,stu1是结构体类型
//stu.age
//stu1 s1; s1.age;