Value Objects -- Rainer Grimm

PortraintRound-1.jpgFrom "Modernes C++":

Value Objects

by Rainer Grimm

From the article:

A value object is a small object whose equality is based on state, but not identity. Typical value objects are money, numbers, or strings. ...

...  For a user-defined type, you have to choose the appropriate equality semantics. ... In C++20, the compiler can auto-generate the equality operator and use it as a fallback for the inequality operator. The auto-generated equality operator applies value equality. To be more precise, the compiler-generated equality operator performs a lexicographical comparison. Lexicographical comparison means that all base classes are compared left to right and all nonstatic members of the class in their declaration order.

I have to add two important points:

Honestly, the example works as expected but does not seem right. ...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.