Newsgroups: comp.lang.c++
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!glinj!bobj
From: bobj@gli.com (Robert Jacobs)
Subject: Virtual function problem.
Message-ID: <1991May8.205314.23760@gli.com>
Summary: Arguments and return types must match in a virtual function.
Keywords: Virtual functions
Organization: General Logistics International
Date: Wed, 8 May 91 20:53:14 GMT

Michael Flower writes.
> If I compile the following with the AT&T 2.1 C++ compiler:
> 
> class A {
>         virtual void    fn(char);       // 1
>         virtual void    fn(char *);     // 2
> };
> 
> class B : public A {
>         void    fn(int);
> };
> 
> main() {}
> 
> in the following way, I get.
> 
> "t.c", line 7: warning:  B::fn() hides virtual A::fn()
> "t.c", line 7: warning:  B::fn() hides virtual A::fn()
> 
> Of course B::fn() hides A::fn(). That is why I wrote it! After all A::fn() is
> virtual.
> .....

In the ARM on page 210 Stroustrup writes:

	C++ requires an exact type match between a virtual function in a
	base class and a function overriding it in a derived class.

In other words, for a function to be virtual in respect to its base class,
it must match in:

1)	return type
2)	argument types

int != char != char*

Hence the reason for the warning.

fn(int) is not a virtual function.

--------------------------------------------------------------------------
Robert Jacobs                          
bobj@gli.com
