Article View: comp.std.c++
Article #2973Kind of Annoying
From: John A Hughes
Date: Tue, 16 Apr 1996 20:13
Date: Tue, 16 Apr 1996 20:13
70 lines
2282 bytes
2282 bytes
[Moderator's note: This article is crossposted between comp.std.c++
and comp.lang.c++, and followups have been set to comp.std.c++. mha]
The following doesn't compile, because the calls to foo look ambiguous
to the compiler:
template<class T>
class Goo {
public:
void foo(T *) {}
};
class A {
};
class B {
};
class C : public Goo<A>, public Goo<B> {
};
main() {
A a;
B b;
C c;
c.foo(&a);
c.foo(&b);
}
Why is this? Why doesn't the mechanism that checks for which function to call
look at the function signature instead of just the name? I presume this is
related to the following:
class A {
public:
void goo(A*) {}
};
class B : public A {
public:
void goo(B*) {}
};
class C : public B {
};
main() {
A a;
B b;
C c;
c.goo(&a);
c.goo(&b);
}
which won't compile because B::goo hides A::goo (even though again they
have different signatures). What's the interest of a having function hide
another with a totally different prototype simply because their names match?
Of course I can make these things compile by explicitly disambiguating in each
case, but it's annoying and I can't think of any benefit to this behavior. Why
does it work this way?
jah
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4kjpfq$r3k@news2.cais.com>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: jah@cais.cais.com (John A Hughes) Newsgroups: comp.std.c++,comp.lang.c++ Subject: Kind of Annoying Followup-To: comp.std.c++ Date: 16 Apr 1996 13:13:07 PDT Organization: Capital Area Internet Service info@cais.com 703-448-4470 Approved: austern@isolde.mti.sgi.com Message-ID: <4kjpfq$r3k@news2.cais.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 11 Apr 1996 20:19:06 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMXP/VEy4NqrwXLNJAQFuPwH/Q6o/SSJmxb3DnTkvRs+DWmODj7n73rf4 U1EVzDIFqMvYpK9UBf/rd9Dntmc3c+ibJpSGKdBUNliSJOElRBE6zQ== =Y+iN Originator: austern@isolde.mti.sgi.com