This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: g++: declaration of a friend from within a namespace
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Matthias Kaehlcke <matthias at kaehlcke dot net>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 02 Jun 2008 17:47:37 -0300
- Subject: Re: g++: declaration of a friend from within a namespace
- References: <20080602161728.GE8734@traven>
On Jun 2, 2008, Matthias Kaehlcke <matthias@kaehlcke.net> wrote:
> namespace ns { class MyClass { friend MyClass ::operator+(MyClass,
> MyClass); private: int attribute; }; }
This is parsed as MyClass::operator+ (whitespace is not significant),
so you end up missing the return type.
> when removing the default namespace specifier ('::') from the friend
> declaration the error message changes to:
Then the friend declaration injects the name in the enclosing
namespace ns, so that's where you'd have to define it. A definition
in the global namespace doesn't match, so it isn't granted access to
private members.
> i can't figure out what would be the correct friend declaration with
> the operator in the default namespace.
Adding parentheses around the declarator id (::operator+) should work.
--
Alexandre Oliva http://www.lsd.ic.unicamp.br/~oliva/
Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org}
FSFLA Board Member ÂSÃ Libre! => http://www.fsfla.org/
Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org}