Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Sychronizing Tw...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 6660 of 9984
Post > Topic >>

Sychronizing Two Cl***** Together

by kupoo <nobody@[EMAIL PROTECTED] > Feb 19, 2006 at 06:37 AM

I have two cl***** that need to synchronize with each other.  That is, I
want to be able to say a = b and b = a.  Would the best way to do that
be to have two friend functions that directly mess with the internals of
cl***** A and B synchronizing one with the other or vice versa?  I would
like if I could to have at least a few member functions involved, but I
certainly don't want this:

/* non-friend of class A OR B! */
A& operator=(A& a, B& b) {
     a.setFirstMember(b.getFirstMember());
     a.setSecondMember(b.getSecondMember());
     /* ...ad nauseum */
}

It would be fine if I could do it like b.save(a) and b.load(a), instead
of a = b and b = a, but I'm not sure how to do that right either.  If I
made B::save and B::load take an A& as a parameter, then A would need to
be defined as a class previous to the definition of those functions:

class A {
....
};

class B {
    void save(A& a);
    void load(const A& a);
};

That seems fine and dandy, but for B::save and B::load to save and load
to structure A, they would need to be friends of A.  Otherwise I end up
with the endless nightmare parade of getter/setter functions I mentioned
above, that I do not want.  But B::save and B::load have to be defined
before A can declare itself a friend of them!

class A {
   friend void B::save(A& a);
   friend void B::load(A& a);
   /* Uh oh, compiler's not going to like this. */
....
};

class B {
   void save(A& a);
   void load(A& a);
};

So what do I do?  What are best practices?  What works the best? All I
know is that I have to be able to store the information in an object of
class B into an object of class A, and I have to store the information
in an object of class A into class B.

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
Sychronizing Two Classes Together
kupoo <nobody@[EMAIL P  2006-02-19 06:37:49 
Re: Sychronizing Two Classes Together
Francis Glassborow <fr  2006-02-20 03:40:21 
Re: Sychronizing Two Classes Together
cbarron3@[EMAIL PROTECTED  2006-02-20 05:34:24 
Re: Sychronizing Two Classes Together
benben <benhongh@[EMAI  2006-02-20 05:55:36 
Re: Sychronizing Two Classes Together
kupoo <nobody@[EMAIL P  2006-02-20 19:03:33 
Re: Sychronizing Two Classes Together
kupoo <nobody@[EMAIL P  2006-02-20 19:03:55 
Re: Sychronizing Two Classes Together
Carl Barron <cbarron41  2006-02-22 06:15:50 
Re: Sychronizing Two Classes Together
"johnchx2@[EMAIL PRO  2006-02-22 06:24:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 8:39:25 CDT 2008.