Implementing the LengthProxy Object

Learn how to implement the LengthProxy object for comparing and calculating lengths while preventing misuse.

LengthProxy object

It’s time to implement the LengthProxy class containing a float data member that represents the squared length. The actual squared length is never exposed to prevent users of the class from mixing the squared length with the regular length.

Instead, LengthProxy has a hidden friend function that compares its squared length with a regular length, as follows:

Get hands-on with 1200+ tech skills courses.