C语言和C++中的struct 和typedef struct
生活随笔
收集整理的这篇文章主要介绍了
C语言和C++中的struct 和typedef struct
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
C语言 中
// c typedef struct Student {int age; } S; 等价于 // c struct Student { int age; };typedef struct Student S;
此时 S 等价于 struct Student,但两个标识符名称空间不相同。
另外还可以定义与 struct Student 不冲突的 void Student() {}。
C++ 中
由于编译器定位符号的规则(搜索规则)改变,导致不同于C语言。
一、如果在类标识符空间定义了 struct Student {…};,使用 Student me; 时,编译器将搜索全局标识符表,Student 未找到,则在类标识符内搜索。
即表现为可以使用 Student 也可以使用 struct Student,如下:
总结
以上是生活随笔为你收集整理的C语言和C++中的struct 和typedef struct的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: u盘变了主分区怎么办 U盘主分区丢失怎么
- 下一篇: C++ 中 struct 和 class