Click to See Complete Forum and Search --> : Need help!
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!!!
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();
}
Not really that simple, 'coz B's constructor has several parameters for which I won't have values :-( Any other Ideas?
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?.
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.
your can use friend class to do it .
eg.
class a
{
friend class b;
functionA();
}
b::fuctionB()
{
fuctionA();
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.