Why is there a class keyword in C++?

后端 未结 5 1785
無奈伤痛
無奈伤痛 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 16:14

    Bjarne Stroustrup, the original designer of C++, was strongly inspired by the Simula programming language. That is where he got the class concept and the name "class".

    As indicated in the answer which quoted "Design and Evolution", the real question Bjarne asked himself wasn't "Why introduce a class keyword?". Instead he asked "Should a struct behave similarly to a class?". Bjarne decided that they should. This article from 1997 argues that he made the wrong decision.

提交回复
热议问题