While struct
can behave like a class, it doesn't emphasize the object-orientedness of the langauge. So I think class
was added to the language to emphasize the object-orientedness of C++. It also emphasizes data-encapsulation, as everything in a class is private
by default, whereas struct
doesn't emphasize data-encapsulation, as everything in a struct is public
by default.
Data-encapsulation is one of the principles of object-oriented programming, so I think, making default-access private
is very important. It gives a sense of class-design from the very beginning. Just pretend for a moment that there is no keyword class
in C++, then imagine how many people would have created topics like "why everything in C++ is public by default, as everything in struct is public by default? Is it a characteristic of a language which supports object-oriented programming". To me, it feels that C++ would be lacking the sense of class-design.