This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Virtual function override differing by return type (bug?)
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Virtual function override differing by return type (bug?)
- From: Andrew Birkett <andrew dot birkett at voxar dot com>
- Date: Tue, 18 Jan 2000 17:46:28 +0000
Hi,
Section 10.2 (page 210) of the ARM (section Derived Classes/Virtual
Functions) says that C++ requires an exact type match between a virtual
function in the base class, and a function overriding it in a derived
class. Specifically, overriding a function returning a pointer to a
base class with a function returning a pointer to a derived class is not
allowed.
The following code compiles without complaint under gcc 2.95.2 (x86,
running Solaris) with 'g++ -c test.cc'. MS DevStudio 6.0 gives the
error "overriding virtual function differs only by return type". I
think this is incorrect behaviour by gcc. I can't find mention of this
in the gcc FAQ or BUGS file.
Andrew
// test.cc
class Base
{
};
class Derived : public Base
{
};
class Interface {
public:
virtual Base *Fn() = 0;
};
class Implementation : public Interface {
public:
Derived *Fn();
};