在C++中,之间有什么区别:
struct Foo { ... };
Run Code Online (Sandbox Code Playgroud)
和
typedef struct { ... } Foo;
Run Code Online (Sandbox Code Playgroud) 我是C编程的初学者,但我想知道typedef在定义结构时使用与使用结构之间有什么区别typedef.在我看来,实际上没有区别,他们实现了同样的目标.
struct myStruct{
int one;
int two;
};
Run Code Online (Sandbox Code Playgroud)
与
typedef struct{
int one;
int two;
}myStruct;
Run Code Online (Sandbox Code Playgroud) 我觉得这可能与C语法有关,但我用C++开始编程,所以我不确定.
基本上我已经看到了这个:
struct tm t;
memset( &t, 0, sizeof(struct tm) );
Run Code Online (Sandbox Code Playgroud)
我对这种语法有点困惑,因为通常我希望上面的内容看起来像这样:
tm t;
memset( &t, 0, sizeof(tm) );
Run Code Online (Sandbox Code Playgroud)
这两者之间有什么区别,为什么要使用前者呢?
tm我所指的结构是wchar.h,其定义如下:
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 …Run Code Online (Sandbox Code Playgroud)