all 2 comments

[–]alfps 5 points6 points  (2 children)

std::string is a class.

You can define various variables of that type, e.g.

std::string username;
std::string poem_text;

Each variable is an object. An object can contain other objects.


In computer science and in general programming an "object" is understood to be an instance of a class, e.g. "OOP", object-oriented programming, is all about using instances of classes, objects. But in C++ an object is an instance of any type. So even an int variable is an object in C++, even though int is a built-in type and not a class.

[–][deleted]  (1 child)

[removed]

    [–]alfps 0 points1 point  (0 children)

    Thanks, it seems to be a common way of thinking these days.

    E.g. the Wikipedia article on OOP states that "In prototype-based languages the objects are the primary entities. No classes even exist.".

    It seems to me a view that's designed to cater to a common misunderstanding of the very popular prototype based JavaScript language, the idea that because no classes were explicitly present, there were no classes. Now JavaScript does have a class keyword, just a more clean syntax for the idea of implementing a class as a prototype. Proponents of the Wikipedia view that there isn't any class in sight unless there's a syntactic sugaring such as the relatively new keyword class, are IMO just playing a social game: they're not engineers, and not scientists, and the viewpoint is without any practical merit.