typedef struct should be a C language design is not very reasonable place, the following explanation is still relatively clear.
Notice different in C and C + +
In C, you define a struct type with a typedef:
typedef struct STUDENT
{
int A;
}stu;
Stu stu1;
struct Student stu1;
So when you declare a variable, you can: Stu stu1;
( If there is no TypeDef, you must use struct Student stu1; to declare)
The Stu here is actually the alias of struct student. Stu==struct Student
////////////////////////////////////////////////////////////////////////////////////////////////////////////
In addition here also can not write Student (so also cannot struct Student stu1;, must be Stu stu1;)
typedef struct
{
int A;
}stu;
Stu stu1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
But in C + + is very simple, direct
struct Student
{
int A;
};
Student STU2;
Then the structure body type student is defined, and the STU2 is directly student when the variable is declared.
In C + +, if you use a TypeDef, it makes a difference:
struct Student
{
int A;
}STU1;//STU1 is a variable
stu1.a;
typedef struct STUDENT2
{
int A;
}STU2;//STU2 is a structural body type =struct Student
STU2 S2;
s2.a;
Direct access to stu1.a when used
But STU2 must first stu2 the S2;
Then s2.a=10;