This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]