Why is there a class keyword in C++?

后端 未结 5 1798
無奈伤痛
無奈伤痛 2020-12-11 15:50

This question came to my mind when I learned C++ with a background of C. Even if there was a struct why did Stroustrup felt it was necessary to introduce the <

5条回答
  •  攒了一身酷
    2020-12-11 15:55

    As David says, structs are public by default, classes are private by default. The larger point is that adding object orientation to C was a big change, and giving developers ways to express themselves accurately is an important part of designing a language.

    As it turns out, the distinction between struct and class is quite minor from a technical point (default-public vs default-private), but in programmers' minds, the distinction is quite large. Adding the keyword was an important way to emphasize the OO nature of C++.

提交回复
热议问题