|
-
May 25th, 1999, 05:17 AM
#1
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!!!
-
May 25th, 1999, 05:43 AM
#2
Re: Need help!
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
#3
Re: Need help!
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
#4
Re: Need help!
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
#5
Re: Need help!
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
#6
Re: Need help!
your can use friend class to do it .
eg.
class a
{
friend class b;
functionA();
}
b::fuctionB()
{
fuctionA();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|