Thread View: comp.std.c++
3 messages
3 total messages
Started by John A Hughes
Tue, 16 Apr 1996 20:13
Kind of Annoying
Author: 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
]
Re: Kind of Annoying
Author: Fergus Henderson
Date: Wed, 17 Apr 1996 14:57
Date: Wed, 17 Apr 1996 14:57
46 lines
1774 bytes
1774 bytes
jah@cais.cais.com (John A Hughes) writes:
>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 C : public Goo<A>, public Goo<B> {
I believe that if you add
public:
using Goo<A>::foo;
using Goo<B>::foo;
here in the declaration of class C, this will resolve the ambiguities
in the calls below:
>};
>
>main() {
> A a;
> B b;
> C c;
> c.foo(&a);
> c.foo(&b);
>}
Unfortunately, however, none of the C++ compilers that I have access
to support this yet.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Re: Kind of Annoying
Author: Srinivas Vobilisetti
Date: Thu, 18 Apr 1996 00:50
Date: Thu, 18 Apr 1996 00:50
12 lines
1266 bytes
1266 bytes
I too agree with you, Jah. The ANSI/ISO C++ introduced the reserved word 'using' which will help you to show the base class hidden functions in the derived class interface. Then you don't need to explicitly disambiguate each time. Srinivas Vobilisetti --- [ comp.std.c++ is moderated. To submit articles: try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ] [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ] [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads