Re: operator== for aggregate types / member wise comparison
"Seungbeom Kim" <musiphil@bawi.org>
How would you solve this problem?
class BigData {
// here are only data members...
}
class Big : public BigData {
Big(const Big& other) : BigData(other)
{
// logging stuff
}
}
It requires a complete rewriting of the members, which is too intrusive.
Not generally. the things you lose are constructors, that are not inherited
currently, and private/public. The latter can be solved by separate 'data'
structs used with the proper keyword on inheritance.
For ctors you must write forwarders by hand. For elaborated classes that is
not likely a big problem, but certainly a pain.
Instead of mentioning the members in the copy constructor, you have to
move as many members and update all their uses, so how much does this
save?
IMO client code does not notice such splitting in any way.
Moreover, you cannot enforce that all the data members belong to
BigData and not Big; someone could add a data member to Big and that
could go unnoticed, couldn't it?
Enforcing correct development is a peopleware and process problem -- that
can be solved by having code reviews on change check in. Certainly if
anyone can hack the code in any way liked without control, the result will
be chaos. And any magic the language gives can be circimvented, suppose you
had some keyword, what prevents it being deleted or #defined away?
While most systems we have today have 'object browser', and it is not hard
to discover things like undue members. (Too bad I didn't see an API to work
with the browse info, then simple scripts run against it could solve that
problem too, and be generally useful)
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]