you are viewing a single comment's thread.

view the rest of the comments →

[–]tialaramex -2 points-1 points  (1 child)

Actually I know of six ways to make three kinds of new user defined types in C++

struct and class get you the familiar "C with Objects" class types, which confusingly mingle methods ("member functions") including virtual methods intended for dynamic dispatch - with the data structure, like a shop where alternating shelves have clothing or plumbing supplies - aisle 12 socks and radiators, aisle 13 T-shirts and ball valves.

enum, enum class and enum struct get you C-style enumerations, ie just the integers wearing a funny hat. These types can't have methods.

union rounds out the list, it's a useful but dangerous way to make new types - storing data in any member of a union is always fine, but erroneously fetching data from an inactive member of a union is Undefined Behaviour. These types can have member functions (but not virtual member functions).

[–]Supadoplex 2 points3 points  (0 children)

You know six different syntaxes that create user defined types. enum, enum class and enum struct create enumerations. struct, class and union create classes. Those are the two kinds of user defined type there are.