|
-
September 4th, 2002, 07:10 AM
#1
Friend Class
Helo,
I have a class say A;
class A
{
public:
Test();
friend class B;
};
I have another class B;
class B
{
void Hello()
{
}
};
What I need here is,from class B's Hello() Function ,I want to call the class A's Test() function by using friend class.
How Can I do this...
Thanks...
-
September 4th, 2002, 08:04 AM
#2
The simpliest way is to create class A object and to call test() function.But in this way You don't need friendsheep between classes because of publicy of test() function.
The keyword friend a mostly used when You have protected or private elements in class A , and want to call/read them from class B.
For more infos look in stdlib templates like list
(list.h) , and you will see when keyword friend are used (in iterators for exmple )
Take a look arround .... // Limp Bizkit
"Women - always in trouble with them, but can't live without them." June, 1991 Ayrton Senna.
-
September 4th, 2002, 08:51 AM
#3
You need an instance of type A to call a non-static method in A, regardless of friendship.
Note: use of friend usually indicates a bad design.
Jeff
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
|