Click to See Complete Forum and Search --> : Friend Class


Kohinoor24
September 4th, 2002, 07:10 AM
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...

Snakee
September 4th, 2002, 08:04 AM
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

jfaust
September 4th, 2002, 08:51 AM
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