Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   derived class is friend class to base class (http://www.go4expert.com/forums/derived-class-friend-class-base-class-t3950/)

sharmila 20Apr2007 12:20

derived class is friend class to base class
Hi all,
I saw a code in which derived class is friend class of base class. I did not understand it's purpose. We can access all the fun.s and var.s of base class in derived class (since it is friend to base), if we want the total control of base then why can't we make every thing as protected , instead of saying derived is friend to base?


class Base {
  // code
  friend class Derived1;
  friend class Derived2;

class Derived1 : public Base {
// code

class Derived2 : public Base {
// code

I thought may be for other derived class it should not give total control, and so they made derived as friend, but this base class is inherited by two derived classes and both are friends to base. No other class is derived from this base. Can you explain me when can we use the concept of derived class is friend to base class ( in real time)?

and one more doubt is how friend is implemented internally? means how it is represented in object table?


All times are GMT +5.5. The time now is 09:13.