In the book The C++ Programming Language, the author claims that, for the following class design,
class complex{
double re, im;
public:
double real( ) const { return re;}
double imag( ) const { return im;}
};
Given real() and imag(), we can define all kinds of useful operators without granting them direct access to the representation of complex.
How to understand this statement? Where do we need direct access and where do we need indirect access?
The author also gives the following example.
inline bool operator==(complex a, complex b)
{
return a.real( )==b.real() && a.imag () ==b.imag( );
}
How is this given example related to the author's statement given in the above.