C structure and C++ structure

后端 未结 6 877
挽巷
挽巷 2020-12-13 04:35

Could anybody please tell me what is the main difference between C & C++ structures.

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 04:55

    In C++ struct and class are the exact same thing, except for that struct defaults to public visibility and class defaults to private visiblity.

    In C, struct names are in their own namespace, so if you have struct Foo {};, you need to write struct Foo foo; to create a variable of that type, while in C++ you can write just Foo foo;, albeit the C style is also permitted. C programmers usually use typedef struct {} Foo; to allow the C++ syntax for variable definitions.

    The C programming language also does not support visibility restrictions, member functions or inheritance.

提交回复
热议问题