gcc does not allow a private member function to be a friend of another class

Denner, Brett brett.denner@lmco.com
Tue Jul 27 17:23:00 GMT 2004


In Stroustrup's "The C++ Programming Language," section 11.5, the
following example is given:

=====================================
class List_iterator {
    int* next();
}

class List {
    friend int* List_iterator::next();
}
=====================================

When I compile it with gcc, I get the following output:

=====================================
    test.cpp:2: error: `int* List_iterator::next()' is private
    test.cpp:6: error: within this context
=====================================

Stroustrup's book seems to indicate that this should work.

Here's my output from gcc -v:

=====================================
Reading specs from
/home/brett/local/lib/gcc/i686-pc-linux-gnu/3.4.1/specs
Configured with: ../gcc-3.4.1/configure --prefix=/home/brett/local
--enable-languages=c,c++,f77,java
Thread model: posix
gcc version 3.4.1
=====================================

A similar problem occurs if next() is a protected member, but not if
next() is a public member.

Thanks,

Brett



More information about the Gcc-bugs mailing list