Afficher un message
Vieux 05/04/2008, 02h07   #3
me.devilspride@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: for correct class structure

On Apr 4, 7:28pm, "Jim Langston" <tazmas...@rocketmail.com> wrote:
> me.devilspr...@gmail.com wrote:
> > Hi,

>
> > I have two classes A and B as follows.
> > A has member data X and member functions P, Q, R. All P,Q,R access X
> > and Q calls P.
> > B is a derived class of another Class(which I don't go into) with
> > member functions D, E.

>
> > P in A calls D in B.
> > D in B calls Q, R in A.

>
> > It's a big recursion. Everything works if I move D,E to class A. But
> > how do I achieve above as value of X need to be used through the whole
> > program execution? I wanted to know if what I am trying to accomplish
> > is something doable or I need to redesign my class structures.

>
> > Thanks

>
> How about showing some actual code? Even something like:
>
> class A
> {
> int X;
> public:
> P() {}
> Q() {}
> // ...
>
> };
>
> etc..
>
> What your'e trying to describe in words is not clear.
>
> --
> Jim Langston
> tazmas...@rocketmail.com


I am sorry for that

class A {
int X;
public:
P() { Q(); }
Q() { D(); R(); }
R() { uses X }
};

class B: public someclass {
//inherited data from someclass
public:
D() {
Q(); //end condition for recursion depends on X
R();
}
};

I can't create D() in A as D() access private data in B. But D() calls
both Q() and R() and value of X has to be same everywhere. i.e. R()
called from D access the same X value that was used by class A. I
guess I need to pass around this pointer of A's object or X. I guess
it shouldn't be difficult but I am just blocked.
Hope this s.
  Réponse avec citation
 
Page generated in 0,06319 seconds with 9 queries