What Is The Use Of Friend Function In PHP

What Is The Use Of Friend Function In PHP


  • 21 Dec, 2011

    Friend functionsSometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.class mylinkage{private:mylinkage * prev;mylinkage * next;protected:friend void set_prev(mylinkage* L, mylinkage* N);void set_next(mylinkage* L);public:mylinkage * succ();mylinkage * pred();mylinkage();};void mylinkage::set_next(mylinkage* L) { next = L; }void set_prev(mylinkage * L, mylinkage * N ) { N->prev = L; }Friends in other classesIt is possible to specify a member function of another class as a friend as follows:class C{friend int B::f1();};class B{int f1();};It is also possible to specify all the functions in another class as friends, by specifying the entire class as a friend.class A{friend class B;};

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.