This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Virtual function override differing by return type (bug?)


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();
};

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]