* Pure virtual member and namespaces.
@ 1998-03-21 10:36 Savas Parastatidis
1998-03-24 0:03 ` Martin von Loewis
0 siblings, 1 reply; 2+ messages in thread
From: Savas Parastatidis @ 1998-03-21 10:36 UTC (permalink / raw)
To: egcs
Dear all,
I think there is a problem while compiling the following example using the
latest snapshot of egcs:
#include <iostream>
using namespace std;
namespace FooNamespace
{
class Foo
{
public:
Foo() {}
virtual void f() = NULL;
};
}
class MyClass : public FooNamespace::Foo
{
public:
MyClass() {};
void f() { cout << "Boom" << endl; }
};
void main()
{
MyClass* x = new MyClass;
FooNamespace::Foo* foo = x;
foo->f();
}
The message I get is:
/tmp/cca11232.s: Assembler messages:
/tmp/cca11232.s:257: Fatal error: Symbol __tfQ212FooNamespace3Foo already
defined.
Any ideas? Am I doing something wrong? Ah, the problem I talked about in a
previous message persists. I do not send this to comp.std.c++ as it is my
understanding that the following example complies with the standard. Please,
comment...
#include <map>
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);
}
namespace X
{
class foo2
{
public:
foo2()
{
MyMap m;
foo1 f1, f2;
m.insert(MyMap::value_type(f1, 1));
m.insert(MyMap::value_type(f2, 1));
}
private:
typedef std::map<foo1, int> MyMap;
};
}
int main()
{
X::foo2 f2;
}
Thank you very much,
--
Savas Parastatidis, PhD. Student, Claremont Bridge 353
Dept. of Computing Science, University of Newcastle, NE1 7RU, UK
e-mail: Savas.Parastatidis@ncl.ac.uk, tel. +44 191 222 8789
URL: http://www.ncl.ac.uk/~n5831124 , fax +44 191 222 8232
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Pure virtual member and namespaces.
1998-03-21 10:36 Pure virtual member and namespaces Savas Parastatidis
@ 1998-03-24 0:03 ` Martin von Loewis
0 siblings, 0 replies; 2+ messages in thread
From: Martin von Loewis @ 1998-03-24 0:03 UTC (permalink / raw)
To: Savas.Parastatidis; +Cc: egcs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1594 bytes --]
> 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 <map>
>
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-03-24 0:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-21 10:36 Pure virtual member and namespaces Savas Parastatidis
1998-03-24 0:03 ` Martin von Loewis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).