This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
gcc does not allow a private member function to be a friend of another class
- From: "Denner, Brett" <brett dot denner at lmco dot com>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 27 Jul 2004 12:23:22 -0500
- Subject: 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