Topic: Friend of self


Author: David R Tribble <dtribble@technologist.com>
Date: 1999/03/04
Raw View
[I don't have my C++ spec handy, so...]

Is the following declaration meaningful (and legal)?

    class Foo
    {
        friend class Foo;
        ...
    };

I know that function members of a class already have access to all
of the data members of other objects of the same class type (unlike
other languages such as Eiffel), but does explicitly declaring a
class to be a friend of itself have any harmful effects?

-- David R. Tribble, dtribble@technologist.com --


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: sbnaran@localhost.localdomain (Siemel Naran)
Date: 1999/03/04
Raw View
On 4 Mar 1999 00:50:17 GMT, David R Tribble <dtribble@technologist.com> wrote:

>Is the following declaration meaningful (and legal)?
>
>    class Foo
>    {
>        friend class Foo;
>        ...
>    };
>
>I know that function members of a class already have access to all
>of the data members of other objects of the same class type (unlike
>other languages such as Eiffel), but does explicitly declaring a
>class to be a friend of itself have any harmful effects?

My compilers give me a warning that the friend declaration has no
effect, so I guess there are no harmful effects.  The warning arises
in template classes.

template <class T>
class Foo
{
   template <class U> friend Foo<U>;
   public:
};

--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]