Results 1 to 6 of 6

Thread: What does Friend class mean?

  1. #1
    Join Date
    Dec 2009
    Posts
    32

    What does Friend class mean?

    Hello Guys,

    I am new to the programming field. I have one question regarding the classes. I am not able to understand the friend class concept. I want to be aware about the What friend class in object oriented programming. It essential to know this as the class is the main part of the object oriented programming. I have referred lot's of books for this without any luck. I wonder if anyone let me know what is friend class in OOP. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: What does Friend class mean?

    Hi,

    Using friend class we can access the another class component and it is done by without creating that component as public. So it prevent the overhead which is created by calling the member function for getting private component. See following example in which a class 'Vqt' is 'friend class':
    Code:
    class Vq 
    {
    
    friend class Vqt;
    int value;
    ...
    
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: What does Friend class mean?

    Developing a friend class or a function enables the same function or class can access private members (methods, attributes, etc.) in class "host".This means that value stored in variables, and operations can be accessed easily with friend function.
    Example:
    Code:
    class FJE {
    private int bs;
    
    public:
    void display () {}
    
    friend void modify (int Tz);
    };
    
    void modify (int im) (
    c.private = i;
    }
    
    int main ()
    {
    Tz ttt;
    
    modify (ttt, 8);
    
    ttt.afficher ();
    
    return 0;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What does Friend class mean?

    Friends can be either functions or other classes. A Friend class offers privileged access rights to other class. The developer of a class exercise in control theory and technology policy both on friends as member functions of class (if it was not the case, he should obtain permission from those who have written some friends when he wants to change his class). In short it is something that allows a class to offer privileged access rights to another class or function.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What does Friend class mean?

    Member functions and friend class have identical access rights (that is 100% guaranteed). The main difference is that a call to a friend class of the form f (x), then a call to a member function of the form xf (). The main disadvantage of using friend class is that they need an extra line of code to get a dynamic binding (dynamic binding). To use a virtual class, it is necessary that the friend class must calls a virtual member function. This is known as the idiom of the Virtual Friend Function.

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What does Friend class mean?

    Hi friend,

    Refer the following program code, Here I have declared class 'NKT' as friend class and which is called in class 'GBP':
    class GBP
    {
    private:

    //...

    public:

    //...

    friend classNKT;
    }

Similar Threads

  1. Replies: 6
    Last Post: 27-03-2012, 11:54 PM
  2. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  3. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,579,671.32106 seconds with 17 queries