Connecting Tech Pros Worldwide Help | Site Map

struct problem

  #1  
Old September 6th, 2006, 01:15 AM
Jing Yong
Guest
 
Posts: n/a
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, 01:25 AM
Victor Bazarov
Guest
 
Posts: n/a

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, 01:25 AM
Victor Bazarov
Guest
 
Posts: n/a

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, 10:05 AM
Earl Purple
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
Operater < overloading for struct problem Frank answers 14 March 3rd, 2007 01:15 AM
Struct problem netchtech answers 4 February 21st, 2007 07:54 AM
linked list - struct problem Erik answers 9 May 31st, 2006 01:35 AM
struct problem jesse answers 14 November 14th, 2005 04:04 AM
struct problem Bern answers 11 July 22nd, 2005 06:51 PM