what does this friend declaration mean ???

Discussion in 'C++' started by hsharsha@gmail.com, Feb 14, 2006.

  1. Guest

    Consider the below code:

    int main(void)
    {
    class inner
    {};
    friend class inner; /* what does this signify???? */
    return 0;
    }

    what does 'friend class inner' mean in the above code. its not inside a
    class.......

    This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
    not compilable in gnu c++ compiler. gnu c++ compiler will report the
    following error:

    `friend' can only be specified inside a class
    , Feb 14, 2006
    #1
    1. Advertising

  2. benben Guest

    wrote:
    > Consider the below code:
    >
    > int main(void)
    > {
    > class inner
    > {};
    > friend class inner; /* what does this signify???? */
    > return 0;
    > }
    >
    > what does 'friend class inner' mean in the above code. its not inside a
    > class.......


    Nothing. It's illegal.

    >
    > This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
    > not compilable in gnu c++ compiler. gnu c++ compiler will report the
    > following error:


    Ms C++ compiler 12 and 13 are very old. Avoid using them.

    >
    > `friend' can only be specified inside a class
    >


    It says what needs to be said.

    Regards,
    Ben
    benben, Feb 14, 2006
    #2
    1. Advertising

  3. Jim Langston Guest

    <> wrote in message
    news:...
    > Consider the below code:
    >
    > int main(void)
    > {
    > class inner
    > {};
    > friend class inner; /* what does this signify???? */
    > return 0;
    > }
    >
    > what does 'friend class inner' mean in the above code. its not inside a
    > class.......
    >
    > This code is compilable in microsoft c++ compiler 12.0 and 13.0 but
    > not compilable in gnu c++ compiler. gnu c++ compiler will report the
    > following error:
    >
    > `friend' can only be specified inside a class


    The gnu c++ compiler is correct. The Microsoft c++ compiler is wrong.

    friend is used inside a class to state what other classes/functions can
    access it's private members.
    Jim Langston, Feb 14, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    2,170
    Rolf Magnus
    May 16, 2005
  2. kelvSYC
    Replies:
    6
    Views:
    7,226
    Richard Herring
    May 17, 2005
  3. franco ziade

    what does this declaration mean?

    franco ziade, Feb 17, 2005, in forum: C Programming
    Replies:
    4
    Views:
    388
    Andrey Tarasevich
    Feb 17, 2005
  4. Klaus
    Replies:
    3
    Views:
    1,065
    Klaus
    Mar 31, 2008
  5. Peter
    Replies:
    2
    Views:
    272
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page