Connecting Tech Pros Worldwide Forums | Help | Site Map

struct problem

Jing Yong
Guest
 
Posts: n/a
#1: Sep 6 '06
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)?
Regards,
Yong jin (~.~E)


Victor Bazarov
Guest
 
Posts: n/a
#2: Sep 6 '06

re: struct problem


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


Victor Bazarov
Guest
 
Posts: n/a
#3: Sep 6 '06

re: struct problem


Jing Yong wrote:
Quote:
[..]
Oh, and I just wanted to mention, this is not a chat room. You post,
you wait, you check if there are any responses, and if there aren't,
you wait more. Do NOT post the same message three times in the span
of six minutes, especially under different subjects. Patience is
a virtue. Develop it.


Earl Purple
Guest
 
Posts: n/a
#4: Sep 6 '06

re: struct problem



Victor Bazarov wrote:
Quote:
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?
There is boost::tuple but I don't think they have extended it as far as
50 members. If C++0x has variadic templates though it should be
possible there.

That doesn't mean, of course, that one should go around making
classes/structs of 50 members.

Closed Thread


Similar C / C++ bytes