C++ struct 关键字用法 [英] C++ struct keyword usage
问题描述
我正在按照本指南设置一个基本的套接字服务器:https://www.geeksforgeeks.org/socket-programming-cc/
I'm setting up a basic socket server following this guide: https://www.geeksforgeeks.org/socket-programming-cc/
所以,我知道当您使用关键字 struct 时,它是为了定义数据结构,但是正如您在示例中看到的那样,它使用结构关键字创建了 sockaddr_in 的实例,但它不是用于创建/定义结构,就是创建实例.
So, I know that when you use the keyword struct it's to define a data structure, but as you can see in the example, it creates an instance of sockaddr_in using the structure keyword, but it's not for creating/defining the structure, it's to create an instance.
所以我想知道为什么在这个定义 sockaddr_in 结构的指南中,他之前放置了 'structure' 关键字,我没有尝试过,它编译正确.
So I'm wondering why in this guide to define a sockaddr_in structure he puts the 'structure' keyword before, I tried it without and it compiles all correctly.
背后有什么原因吗?
推荐答案
使用 struct
声明结构体的实例来自 C.它在 C++ 中是可选的.
using struct
when declaring an instance of a struct comes from C. It is optional in C++.
这篇关于C++ struct 关键字用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!