Jing Yong wrote:
Quote:
I have a classtruct of over 50 members
>
class A {
public:
type -- 50 members
A(){initialize all members}
friend bool operator==(A&,A&){//my operator goes here
}
>
}B[2];
>
In the operator I have to compare each member of A , and this looks
not good
Any other ways for the comparison of B[0] and B[1] please?
>
Also, in that case how are the values evaluated by the VC6 compiler (I
am using)?
|
There is no other way. In most cases your members have their own equality
semantics, so using, say, 'memcmp' is probably not a good idea. You could,
of course, write your objects out to a, say, stringstream, and then compare
the resulting strings, but that would require defining operator<< for the
class (if you don't have it yet).
One thing comes to mind: if you have 50 members, how do you manage such
a monster? It is a nightmare to maintain it. If somebody needs to change
the behaviour or the implementation, how do they begin to make heads or
tails of it? Wouldn't it be better to group related members into some
kind of subclasses and define the behaviour (equality as well) there?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask