dfg*_*dfg 13 c c++ data-structures
有什么区别:
typedef struct part
{
int a;
} Part;
Run Code Online (Sandbox Code Playgroud)
和
typedef struct
{
int a;
} Part;
Run Code Online (Sandbox Code Playgroud)
我知道第二个是"匿名",但它们有什么不同吗?
Eoi*_*rst 19
除了Mike Seymour的回答,这是一个原因的例子:
链接列表例如
// this works
typedef struct part {
struct part *next;
} Part;
// this doesn't work
typedef struct {
struct Part *next;
} Part;
// neither this
typedef struct {
Part *next;
} Part;
Run Code Online (Sandbox Code Playgroud)
Mik*_*our 15
在这两种情况下,您都定义了一种结构类型,以及一种称为Part
该类型的类型别名.
在第一种情况下,您还定义了一个结构名称part
,因此结构类型也可以称为struct part
或仅part
在C++中.
在第二种情况下,结构本身没有名称(因此是"匿名"),并且只能通过类型别名来引用.由于该别名仅在结构定义之后声明,因此结构不能引用自身.
归档时间: |
|
查看次数: |
452 次 |
最近记录: |