g++ does not resolve operator = correctly
Xavier Van Elsacker
xavier@CoWare.com
Mon Jul 3 10:41:00 GMT 2000
g++ 2.95.2 resolves the assignment in the following
piece of code to the pure virtual assign on the base
class, instead of making it a virtual call.
I compiled without any compilation flags, (g++ assign.cc),
on SUN and HP, also tried 2.81 with the same result.
#include <iostream.h>
class base {
public:
virtual const base &operator = (const base &) = 0;
};
class derived : public base {
public:
virtual const base &operator = (const base &rhs);
};
void func(derived *b, derived *c) {
*b = *c;
}
int main() {
derived a;
derived b;
func(&a, &b);
return 0;
}
const base &base::operator = (const base &rhs) {
cout << "base assign called" << endl;
return rhs;
}
const base &derived::operator = (const base &rhs) {
cout << "derived assign called" << endl;
return rhs;
}
More information about the Gcc-bugs
mailing list