Connecting Tech Pros Worldwide Help | Site Map

struct problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 6th, 2006, 12:15 AM
Jing Yong
Guest
 
Posts: n/a
Default struct problem

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)


  #2  
Old September 6th, 2006, 12:25 AM
Victor Bazarov
Guest
 
Posts: n/a
Default 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


  #3  
Old September 6th, 2006, 12:25 AM
Victor Bazarov
Guest
 
Posts: n/a
Default 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.


  #4  
Old September 6th, 2006, 09:05 AM
Earl Purple
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.