g++: declaration of a friend from within a namespace
Alexandre Oliva
aoliva@redhat.com
Mon Jun 2 20:48:00 GMT 2008
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}
More information about the Gcc-help
mailing list