Click to See Complete Forum and Search --> : Need help!


May 25th, 1999, 05:17 AM
I'm kinda new to the Object Orientated style of programming, I have a question that may seem a little silly to most. If I have to classes A and B, and in one of A's member functions I want to call one of B's member functions, how do I do it without using inheritance???
Any help appreciated!!!

May 25th, 1999, 05:43 AM
Declare an object of B in the A's member function where U want to call it, then call it. Simple!!
E.g.
ClassAFunct() {
ClassB ObjectB;
ObjectB.ClassBFunct();
}

May 25th, 1999, 06:02 AM
Not really that simple, 'coz B's constructor has several parameters for which I won't have values :-( Any other Ideas?

May 25th, 1999, 06:07 AM
Is it not possible for U to have another constructor just for this purpose?.
May be it will just initialize everything to 0 or something......
Later U can modify these values.
Does it become too shabby?.

May 25th, 1999, 06:08 AM
Use external variables between the two classes in order to have values for your parameters. This is not a good method but it should get the job done.

May 25th, 1999, 09:52 AM
your can use friend class to do it .

eg.
class a
{
friend class b;
functionA();
}

b::fuctionB()
{
fuctionA();
}