What are the differences between struct and class in C++?

后端 未结 30 3204
盖世英雄少女心
盖世英雄少女心 2020-11-21 05:38

This question was already asked in the context of C#/.Net.

Now I\'d like to learn the differences between a struct and a class in C++. Please discuss the technical d

30条回答
  •  灰色年华
    2020-11-21 06:05

    The difference between class and struct is a difference between keywords, not between data types. This two

    struct foo : foo_base { int x;};
    class bar : bar_base { int x; };
    

    both define a class type. The difference of the keywords in this context is the different default access:

    • foo::x is public and foo_base is inherited publicly
    • bar::x is private and bar_base is inherited privately

提交回复
热议问题