Struct and typedef struct in C language and C++

C language

// c
typedef struct Student {
   
    
    
    int age; 
} S;
等价于
// c
struct Student {
   
    
     
    int age; 
};

typedef struct Student S;
At this time, S is equivalent to struct Student, but the two identifier namespaces are different.
In addition, you can define void Student() {} that does not conflict with struct Student.
In C++,
the compiler's rules for positioning symbols (search rules) have changed, which is different from the C language.
1. If struct Student {...}; is defined in the class identifier space, when Student me; is used, the compiler will search the global identifier table. If Student is not found, it will search within the class identifier.
That is to say, you can use Student or struct Student, as follows:

// cpp
struct Student 

Guess you like

Origin blog.csdn.net/it_xiangqiang/article/details/112977975