struct和typedef struct,在C和C++中的区别。
// struct in C
struct tagStruct_C
{
int test;
} Struct_C;
tagStruct_C Str1; // Wrong, "tagStruct_C" is not a variable name !!!
Struct_C Str2; // Wrong, "Struct_C" is not a variable name !!!
struct tagStruct_C Str3; // OK, "struct tagStruct_C" is a variable name.
Struct_C.test = 10; // OK, "Struct_C" is a variable !!!
// struct in cpp
struct tagStruct_Cpp
{
int test;
} Struct_Cpp;
tagStruct_Cpp Str1; // OK, "tagStruct_Cpp" is a variable name.
Struct_Cpp Str2; // Wrong, "Struct_Cpp" is not a variable name !!!
struct tagStruct_Cpp Str3; // OK, "struct tagStruct_Cpp" is a variable name.
Struct_Cpp.test = 10; // OK, "Struct_Cpp" is a variable.
// typedef struct in C
typedef struct tagStruct_C
{
int test;
} Struct_C;
tagStruct_C Str1; // Wrong, "tagStruct_C" is not a variable name !!!
Struct_C Str2; // OK, "Struct_C" is a variable name.
struct tagStruct_C Str3; // OK, "struct tagStruct_C" is a variable name.
// typedef struct in cpp
typedef struct tagStruct_Cpp
{
int test;
} Struct_Cpp;
tagStruct_Cpp Str1; // OK, "tagStruct_Cpp" is a variable name !!!
Struct_Cpp Str2; // OK, "Struct_Cpp" is a variable name.
struct tagStruct_Cpp Str3; // OK, "struct tagStruct_Cpp" is a variable name.