Bug in handling virtual functions in egcs 1.0.3 and GCC 2.8.1

Jonathan Mohr mohrj@Berio.Augustana.AB.CA
Fri Jul 31 10:52:00 GMT 1998


On 30 Jul 1998, Jason Merrill wrote:

> >>>>> Jonathan Mohr <mohrj@Berio.Augustana.AB.CA> writes:
> 
> > Under GCC 2.7.2.3, this works as expected.  Under GCC 2.8.1 and egcs
> > 1.0.3, it invokes operator= in the Vector class (the base class) instead,
> > even though it has been declared virtual.
> 
> > Is this a bug, or has the definition of standard C++ be revised to
> > disallow virtually overloading operators?
> 
> I'm guessing you have code like
> 
> struct Base {
>   ...
>   virtual Base& operator=(const Base&);
> };
> 
> struct Derived : public Base {
>   ...
>   virtual Derived& operator=(const Derived&);
> };
> 
> and you expect the derived op= to override the base.  This was a
> non-standard cfrontism that g++ supported for a while but has since been
> disabled; it's never been part of standard C++.
> 
> If you want to override the Base op=, you need to define an op= taking a
> const Base&.
> 
> Jason
> 

No, my code overrides the Base op= with a "const Base&" parameter, as in:

  class Derived : public Base {
    ...
    virtual Derived& operator=(const Base&);
  };

In any case, thanks for having a look at my problem.

Regards,
Jonathan Mohr

---
Jonathan Mohr, Associate Professor of Computing Science
Augustana University College, 4901-46 Ave., Camrose, AB, Canada  T4V 2R3
E-mail: mohrj@augustana.ab.ca  Phone: (403) 679-1514  Fax: (403) 679-1129






More information about the Gcc-bugs mailing list