From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martin von Loewis To: Savas.Parastatidis@ncl.ac.uk Cc: egcs@cygnus.com Subject: Re: Pure virtual member and namespaces. Date: Tue, 24 Mar 1998 00:03:00 -0000 Message-id: <199803240728.IAA09619@mira.isdn.cs.tu-berlin.de> References: <000801bd5414$49e6e630$51d0f080@newyork.ncl.ac.uk> X-SW-Source: 1998-03/msg00804.html > I think there is a problem while compiling the following example using the > latest snapshot of egcs: Dear Savas, Thanks for your report. > The message I get is: > /tmp/cca11232.s: Assembler messages: > /tmp/cca11232.s:257: Fatal error: Symbol __tfQ212FooNamespace3Foo already > defined. This does not happen with my current sources, so it should be fixed when I submit them. > #include > > namespace X > { > class foo1 > { > public: > int bar; > friend bool operator<(const foo1&, const foo1&); > }; > } > > bool operator<(const X::foo1& rhs, const X::foo1& lhs) > { > cout << "using this" << endl; > return (rhs.bar < lhs.bar); > } I believe the program you present is not a complete C++ program. In particular, the operator you declare inside X::foo is in fact X::operator<(const X::foo&, const X::foo&). [namespace.memdef] says If a friend declaration in a non­local class first declares a class or function 83) the friend class or function is a member of the innermost enclosing namespace. This is not a problem per se. However, you call it later. The call will find both ::operator< and X::operator<, and determine the call to be ambiguous. Instead, you need to use a qualifier in the friend declaration as allowed in [decl.meaning]. This would give namespace X { class foo1 { public: int bar; friend bool ::operator<(const foo1&, const foo1&); }; } Unfortunately, scoping a friend with global scope is currently not supported by g++. Your best bet will be define the operator inside X. Regards, Martin