This is the mail archive of the gcc-help@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]

Re: g++: declaration of a friend from within a namespace


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}


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