Friendship inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcin Vorbrodt

    Friendship inheritance

    Is friendship inherited? Meaning if:

    class Base {
    public:
    friend FriendClass;
    };

    class Derived : public Base {
    }

    Is FriendClass also a friend of Derived? Or does the friendship need to be
    explicitly granted?

    Thanks,
    Martin


  • Andrey Tarasevich

    #2
    Re: Friendship inheritance

    Marcin Vorbrodt wrote:
    [color=blue]
    > Is friendship inherited? Meaning if:
    >
    > class Base {
    > public:
    > friend FriendClass;
    > };
    >
    > class Derived : public Base {
    > }
    >
    > Is FriendClass also a friend of Derived?[/color]

    No.
    [color=blue]
    > Or does the friendship need to be explicitly granted?[/color]

    Yes.

    --
    Best regards,
    Andrey Tarasevich
    Brainbench C and C++ Programming MVP

    Comment

    • Artie Gold

      #3
      Re: Friendship inheritance

      Andrey Tarasevich wrote:[color=blue]
      > Marcin Vorbrodt wrote:
      >
      >[color=green]
      >>Is friendship inherited? Meaning if:
      >>
      >>class Base {
      >> public:
      >> friend FriendClass;
      >>};
      >>
      >>class Derived : public Base {
      >>}
      >>
      >>Is FriendClass also a friend of Derived?[/color]
      >
      >
      > No.
      >
      >[color=green]
      >>Or does the friendship need to be explicitly granted?[/color]
      >
      >
      > Yes.
      >[/color]

      Just to add (because I think it's well expressed) -- take a look at:



      BTW - reading through the entire FAQ would be a good idea -- and
      remarkably entertaining, too!

      HTH,
      --ag

      --
      Artie Gold -- Austin, Texas

      Comment

      • Shane Beasley

        #4
        Re: Friendship inheritance

        "Marcin Vorbrodt" <mvorbro@eos.nc su.edu> wrote in message news:<bj5b4r$gu 4$1@uni00nw.uni ty.ncsu.edu>...
        [color=blue]
        > Is friendship inherited?[/color]

        Friendship is not inherited, transitive, or reciprocal. Apparently,
        enough people ask this that it's a FAQ:

        <http://www.parashift.c om/c++-faq-lite/friends.html>

        While you're there, read the rest of the FAQs:

        <http://www.parashift.c om/c++-faq-lite/>

        There is much knowledge to be had from those pages. :)

        - Shane

        Comment

        • Big Brian

          #5
          Re: Friendship inheritance

          > Is friendship inherited? Meaning if:[color=blue]
          >
          > class Base {
          > public:
          > friend FriendClass;
          > };
          >
          > class Derived : public Base {
          > }
          >
          > Is FriendClass also a friend of Derived? Or does the friendship need to be
          > explicitly granted?[/color]

          IMHO, you should take 5 minutes and try it with our favorite standard C++ compiler.

          Comment

          Working...