In C++, why struct is in fact class?

后端 未结 6 694
谎友^
谎友^ 2021-01-05 11:13

The other topic and responses there made me ask this question:

Why does C++ allow struct to behave just like class? At one hand, C++ made

6条回答
  •  猫巷女王i
    2021-01-05 11:25

    It allows existing structs to be fitted in with C++ code in a more natural way. For instance, you can add member functions to a struct and inherit from a struct, which wouldn't be possible if structs and classes inhabited different universes.

    Stroustrup's original intent was to avoid a fracturing of the community between the traditional C-style "struct" camp, and the OO "class" crowd. He also cited the benefits of having just one concept instead of two.

提交回复
热议问题