问题描述
我感觉这可能与 C 语法有关,但我的编程生涯是从 C++ 开始的,所以我不确定.
I have a feeling this may be related to C syntax, but I started my programming life with C++ so I am not sure.
基本上我见过这个:
struct tm t;
memset( &t, 0, sizeof(struct tm) );
我对这种语法有点困惑,因为通常我希望上面的内容看起来像这样:
I am a bit confused with this syntax, as normally I would expect the above to instead look like this:
tm t;
memset( &t, 0, sizeof(tm) );
两者有什么区别,为什么用前者代替?
What is the difference between the two, and why is the former used instead?
我所指的结构tm在wchar.h中,定义如下:
The structure tm that I am referring to is in wchar.h, and the definition is as follows:
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
推荐答案
简单的答案是 struct 关键字的存在来限制标识符 tm 的查找仅用户定义的类类型.它可能是为了与 C 兼容,在需要的地方.
The simple answer is that the struct keyword there is present to restrict the lookup of the identifier tm to only user defined class types. It is probably left for compatibility with C, where it is required.
与其他人所说的相反,没有 auto-typedef 这样的东西,C 和 C++ 在如何管理用户定义类型的标识符方面也没有区别.唯一的区别在于查找.
Contrary to what others say, there is no such thing as auto-typedef, nor do C and C++ differ with respect to how the identifiers for user defined types are managed. The only difference is in lookup.
您可以在此处
这篇关于在 C++ 中的变量声明中使用 struct 关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)