Topic: a better friend specification ?


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/07/15
Raw View
gerhard@softline.softline.co.at (Gerhard Langs) writes:

>1.)
>as in the ARM (bottom of page 250) stated, it is impossible to
>compilie the following:

>class Y;

>class X
>{
>private:
> friend void Y::Y(int);
> int GetInternalData();
>};

>This gets an error, that the class Y is undefined.

As explained in the ARM, that rule prevents you from introducing
new member function functions into the class without changing
the class definition.

You have two choices:
1. Include the definition of Y in this module.
2. Use an incomplete declaration of Y and make all members of Y
friends of X.

I don't believe that either solution will result in unwriteable
or unmaintainable programs.
--
Steve Clamage, stephen.clamage@eng.sun.com





Author: gerhard@softline.softline.co.at (Gerhard Langs)
Date: 1995/07/11
Raw View
1.)
as in the ARM (bottom of page 250) stated, it is impossible to
compilie the following:

class Y;

class X
{
private:
 friend void Y::Y(int);
 int GetInternalData();
};

This gets an error, that the class Y is undefined.

However, exactly this situation would fit nicely in MY classes:
I just want ONLY the constructors of Y  to be allowed to access
the private Data of class X.
I don't  like to include the Y-header file because of
increasing dependencies.

I cannot see any problems for the compiler: I just tell him,
that certain functions are allowed to access private data,
and it is not intended to declare the functions (e.g. Y::Y() )


2.)
Even better (?):
Let me specify friends (functions and classes) PER ELEMENT:
This needs a new syntax, like the following:

class Z;
class Y;

class X
{
private:
 int i friends( class Z, Y::Y(int) );     // or: friend( .. )
 int GetPrivateData() friends( class Z, Y::Y(int) );
}

.. similar to the exception specification (ARM p361ff).

Any comments ? I'm not a compiler writer, so pls excuse my wishes ....



                                              MfG

                                                  Langs Gerhard

<-------------------------------------------------------------------->
Langs Gerhard, Softline GesmbH                  gerhard@softline.co.at
Phone: +43/3112/3304                             Fax: +43/3112/3304/25