Hi,
There are two classes A and B.
class A
{
void a1(char )
}
and
class B
{
void b1(char )
}
Now, i need to call a1 function from b1.How this can be done.
Regards,
harsha.
Printable View
Hi,
There are two classes A and B.
class A
{
void a1(char )
}
and
class B
{
void b1(char )
}
Now, i need to call a1 function from b1.How this can be done.
Regards,
harsha.
A simple illustration :
Code:class A
{
public:
void a1(char );
};
class B
{
public:
void b1(char x)
{
A AInstance;
AInstance.a1(x);
}
};
some thoughts. There are many possibilities here and it really depends on what you are doing
1. The class A has nonstatic state and the function a1 uses this state.
the state A holds includes more than the parameters of b1 provide or has scope beyond b1 and or the instantiation of B.
This would imply that you can not just instantiate A inside b1 as indicated. Your options are to
a) have a globally accessable instance of A, such as a singleton instance.
b) pass and instance of A into b1 as a paramater, or into B's constructor and hold the instance of A as a member of B.
2. The function a1 uses no non-static state information from A.
a) Make a1 a static member fucntion of A.
b) a1 should not be a member of A at all.
3. a1 only needs to have scope the body of b1 and can be fully instantiated with the parameters of b1
a) instantiate a local instance of A, as indicated by the previous post.
What is the relationship between these two classes?Quote:
Originally Posted by harshandu
In the current form, you cannot! The only way you can make the call is making the class B a friend of A. Otherwise, the member functions should be public and you call the function using the object of A in B's function. Hope this helps. Regards.
*** Wish you all a very happy new year 2006 ***