Nested is a friend (or not)?

W

werasm

Hi All,

I have this minimal bit of code that I found compiles under Comeau and
EDG++, but not under mingw and VC++8.

class Xc;
class Xx
{
friend class Xc;
static void doIt();
};

class Xc{ struct Impl; };
struct Xc::Impl
{
Impl(){ Xx::doIt(); }
};

Should granting friendship to a class not grant friendship to its
nested classes too? I realise friendship is not inheritable, but
it is really constraining to prohibit nested types (which
effectively is part of that class - stronger relationship than
inheritance).

Is this a bug on the part of VCC and MingW or not?

Kind regards,

Werner
 
A

Alf P. Steinbach

* werasm:
Hi All,

I have this minimal bit of code that I found compiles under Comeau and
EDG++, but not under mingw and VC++8.

class Xc;
class Xx
{
friend class Xc;
static void doIt();
};

class Xc{ struct Impl; };
struct Xc::Impl
{
Impl(){ Xx::doIt(); }
};

Should granting friendship to a class not grant friendship to its
nested classes too? I realise friendship is not inheritable, but
it is really constraining to prohibit nested types (which
effectively is part of that class - stronger relationship than
inheritance).

Is this a bug on the part of VCC and MingW or not?

The rules for nested classes have been revamped in C++0x (or will be).

There was a tread about this recently in [comp.lang.c++.moderated], or perhaps
in [comp.std.c++], but I think it was in the first group -- would be nice if
you posted a link if u find it! :)

Anyway, as I recall the rules for nested classes have swung back and forth even
with the current standard. It seems it's one of those *dirty* corners of the
language. So, best not rely on friendship being transitive to nested classes.


Cheers & hth.,

- Alf
 
F

Fraser Ross

On a similar issue where the standard has changed after the 2003
standard Comeau continued with the 2003 wording. Comeau appears to
sometimes implement changes since the 2003 standard.

Fraser.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top