Re: g++ 4: Unrecognised Friendship [REPOST/CROSS-POST]

Discussion in 'C++' started by red floyd, Aug 4, 2005.

  1. red floyd

    red floyd Guest

    JH Trauntvein wrote:
    > red floyd wrote:
    >
    >>JH Trauntvein wrote:
    >>
    >>>Consider the following example:
    >>>
    >>>namespace n1
    >>>{
    >>> class cn1_base;
    >>>
    >>>
    >>> namespace n1_helpers
    >>> {
    >>> class helper1
    >>> {
    >>> private:
    >>> int private_member;
    >>> friend class cn1_base;
    >>> };
    >>> };
    >>>
    >>>
    >>> class cn1_base
    >>> {
    >>> public:
    >>> void foo()
    >>> {
    >>> n1_helpers::helper1 helper;
    >>> helper.private_member = 1;
    >>> }
    >>> };
    >>>};
    >>>
    >>>
    >>>While this compiled with earlier versions of G++, G++ version 4.x fails
    >>>to compile this and gives the following message:
    >>>
    >>> 'int n1::n1_helpers::helper1::private_member' is prviate within this
    >>> context
    >>>
    >>>Fortunately, I can work around this by changing the friend declaration
    >>>to the following:
    >>>
    >>> friend class n1::n1_base;
    >>>
    >>>Is this a bug in the compiler or have I misunderstood something about
    >>>friendship declarations?

    >>
    >>See Standard paragrah 7.3.1.2, subparagraph 3. "If a friend declaration
    >>in a non-local class first declares a class or function, the friend
    >>class or function is a member of the innermost enclosing namespace."
    >>
    >>Sounds to me like it was a bug in earlier g++ versions.

    >
    >
    > It seems to me that the key here is in the phrase, "first declares a
    > class or function". The sample code that I provided had a forward
    > declaration of the class in the appropriate namespace that the
    > friendship declaration should have used.


    I am reposting this with a cross-post to comp.lang.c++, because this is
    not just a compiler issue, but a language issue.

    I believe that in this case, the friend declaration is in fact the first
    declaration of n1_base, and that therefore 7.3.1.2/3 applies.
    red floyd, Aug 4, 2005
    #1
    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. JH Trauntvein

    G++ 4: Unrecognised Friendship

    JH Trauntvein, Aug 10, 2005, in forum: C++
    Replies:
    4
    Views:
    368
    Victor Bazarov
    Aug 10, 2005
  2. Poor Yorick

    __future__ and unrecognised flags

    Poor Yorick, Dec 12, 2008, in forum: Python
    Replies:
    0
    Views:
    249
    Poor Yorick
    Dec 12, 2008
  3. Poor Yorick
    Replies:
    0
    Views:
    259
    Poor Yorick
    Dec 13, 2008
  4. Steve Holden
    Replies:
    1
    Views:
    379
    Rhamphoryncus
    Dec 14, 2008
  5. SteveR

    request format unrecognised

    SteveR, Apr 25, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    101
    SteveR
    Apr 25, 2005
Loading...

Share This Page