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]

g++ does not resolve operator = correctly


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

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