Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > G++ 4: Unrecognised Friendship

Reply
Thread Tools

G++ 4: Unrecognised Friendship

 
 
JH Trauntvein
Guest
Posts: n/a
 
      08-10-2005
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:rivate_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?

Regards,

Jon Trauntvein

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      08-10-2005
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:rivate_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?


7.3.1.2/3. I think it says essentially that the name declared in a friend
declaration is presumed to exist at the same namespace level as the class
in which it is declared. IOW, since 'helper1' is in 'n1::n1_helpers'
namespace, when it declares 'cn1_base' as its friend, the compiler assumes
that 'cn1_base' is the name of a class in 'n1::n1_helpers' namespace.

V
 
Reply With Quote
 
 
 
 
red floyd
Guest
Posts: n/a
 
      08-10-2005
Victor Bazarov wrote:
> JH Trauntvein wrote:
>> [redacted]


> 7.3.1.2/3. I think it says essentially that the name declared in a friend
> declaration is presumed to exist at the same namespace level as the class
> in which it is declared. IOW, since 'helper1' is in 'n1::n1_helpers'
> namespace, when it declares 'cn1_base' as its friend, the compiler assumes
> that 'cn1_base' is the name of a class in 'n1::n1_helpers' namespace.
>
> V


I gave him the same answer, and he didn't like it.
 
Reply With Quote
 
JH Trauntvein
Guest
Posts: n/a
 
      08-10-2005

Victor Bazarov 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:rivate_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?

>
> 7.3.1.2/3. I think it says essentially that the name declared in a friend
> declaration is presumed to exist at the same namespace level as the class
> in which it is declared. IOW, since 'helper1' is in 'n1::n1_helpers'
> namespace, when it declares 'cn1_base' as its friend, the compiler assumes
> that 'cn1_base' is the name of a class in 'n1::n1_helpers' namespace.



Thank you for your reply. I am not wishing to argumentative here but I
feel that there is some potential ambiguity either in the standard or
in my understanding of it

The wording that the standard uses in the case of friendship
declarations is that the class will be assumed to be in the most local
namespace if the class is "first declared". I am unsure about what
"first declared" means but would interpret the forward declaration of
class cn1_base as being the "first declaration" and that, because of
this, the clause that you cite should not have any effect.

Regards,

Jon Trauntvein

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      08-10-2005
JH Trauntvein wrote:
> [...] I am not wishing to argumentative here but I
> feel that there is some potential ambiguity either in the standard or
> in my understanding of it
> [..]


Then I recommend seeking advice from comp.std.c++. That's where the
Standards Committee members hang out and that's where the language lawyers
dispense their wisdom.

V
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad or unrecognised image header. gas@get2net.dk Digital Photography 1 12-08-2005 04:16 PM
Bad or unrecognised image header. Iceman Digital Photography 0 12-08-2005 02:39 AM
Re: g++ 4: Unrecognised Friendship [REPOST/CROSS-POST] red floyd C++ 0 08-04-2005 03:59 PM
Help - Unrecognised drive Richard Webb Windows 64bit 3 05-17-2005 09:38 AM
Help with unrecognised files Mike Day DVD Video 0 03-28-2005 01:10 PM



Advertisments