Re: Why "const rect& rhs" is used here?
I guess I should note that in C++ there *is* an analog to the void* solution
for regular C structs. And that is what is called the "factory method".
The void* solution to the problem of getting rid of any dependency on the
form of the data structure was to reduce access to the underlying structure
to *functions ONLY* and to save off an object with an "unknown" structure.
The factory method does exactly the same thing. We define a "class" which
has no data in it at all, only functions. The functions are defined as "pure
virtual" meaning that they have no implementations. Here's an example:
virtual void GetName (char* cszName, sisze_t cntSize) = 0;
virtual void SetName (const char* cszName) = 0;
and then someone writes a CPP file exporting exactly one function:
STUDENT_RECORD* CreateStudentRecord ();
This is exactly the C/void* solution translated to C++. CreateStudentRecord
will create an instance of an object which implements the two methods given,
and we can change that file to our heart's content without affecting anyone
using "STUDENT_RECORD*"s. The idea is that the implementation and/or
structures used are "unknown" to the outside world, just as void* is an
Incidentally, this is the basis of COM (Common Object Model) which uses a
similar method accomplishing the same thing. In COM the implementations and
structures are usually in DLL's which are "registered" with the operating
system. There is a type of derivation in COM for every object. Every object
is an instance of a special object called, you guessed it, "IUnknown"
- Alan Carre