Difference between 'struct' and 'typedef struct' in C++?

前端 未结 8 1647
忘了有多久
忘了有多久 2020-11-21 06:12

In C++, is there any difference between:

struct Foo { ... };

and:

typedef struct { ... } Foo;
相关标签:
8条回答
  • 2020-11-21 06:46

    Struct is to create a data type. The typedef is to set a nickname for a data type.

    0 讨论(0)
  • 2020-11-21 06:47

    There is no difference in C++, but I believe in C it would allow you to declare instances of the struct Foo without explicitly doing:

    struct Foo bar;
    
    0 讨论(0)
提交回复
热议问题