CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Friend Class

  1. #1
    Join Date
    Oct 2001
    Posts
    745

    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...

  2. #2
    Join Date
    May 2002
    Location
    Lithuania
    Posts
    4

    Thumbs up

    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.

  3. #3
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    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
  •  





Click Here to Expand Forum to Full Width

Featured