* -Woverloaded-virtual : why ?
@ 2005-08-18 14:10 Matthew Jones
2005-08-18 14:36 ` Peter Doerfler
0 siblings, 1 reply; 2+ messages in thread
From: Matthew Jones @ 2005-08-18 14:10 UTC (permalink / raw)
To: gcc-help
Why does the following code generate an error ?
This error is described in the gcc manual under the C++ -Woverloaded-virtual
flag. I can't see why gcc can't generate a call to A::f(Y). This exactly
against the behaviour one would expect under the basic principles of
polymorphism.
(gcc 3.4.3).
struct X{};
struct Y{};
struct Z{};
struct A
{
virtual void f(X);
virtual void f(Y);
virtual void f(Z);
};
struct B: public A
{
virtual void f(X);
};
void Test (void)
{
B b;
X x;
Y y;
b.f(x);
b.f(y); // error: no matching function for call to 'B::f(Y&)'
}
--
Matthew JONES
http://www.tandbergtv.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: -Woverloaded-virtual : why ?
2005-08-18 14:10 -Woverloaded-virtual : why ? Matthew Jones
@ 2005-08-18 14:36 ` Peter Doerfler
0 siblings, 0 replies; 2+ messages in thread
From: Peter Doerfler @ 2005-08-18 14:36 UTC (permalink / raw)
To: gcc-help
Hi Matthew.
Take a look at
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.7
You are hiding all A::f() by declaring a B::f().
'using' should help.
HTH, Peter
On Thursday 18 August 2005 16:10, Matthew Jones wrote:
> Why does the following code generate an error ?
> This error is described in the gcc manual under the C++
> -Woverloaded-virtual flag. I can't see why gcc can't generate a call to
> A::f(Y). This exactly against the behaviour one would expect under the
> basic principles of polymorphism.
> (gcc 3.4.3).
>
>
> struct X{};
> struct Y{};
> struct Z{};
>
> struct A
> {
> virtual void f(X);
> virtual void f(Y);
> virtual void f(Z);
> };
>
> struct B: public A
> {
> virtual void f(X);
> };
>
> void Test (void)
> {
> B b;
> X x;
> Y y;
>
> b.f(x);
> b.f(y); // error: no matching function for call to 'B::f(Y&)'
> }
>
> --
> Matthew JONES
> http://www.tandbergtv.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-08-18 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-18 14:10 -Woverloaded-virtual : why ? Matthew Jones
2005-08-18 14:36 ` Peter Doerfler
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).