[gnu.g++.help] g++

elkassas@eb.ele.tue.nl (sherif el kassas) (06/21/91)

Hi all,
I'm using g++ version 1.37.1 (based on GCC 1.37)
on apollo systems running SR10.{2,3}
Now, I've got this MI example. The class structure
looks like this:

 B1   B2
   \ /
    D

All classes define two virtual methods called x and y.
My problem is that if i call method x of a D object
METHOD y IS EXECUTED.
(when using a pointer to the object, see void f(D* v))
To make it more interesting, if i swap the lines
labeled // 1 and // 2, the bug goes away.

Am i doing something wrong, or is this a g++ MI bug ?

Thanks,
Sherif

----------------test.cc----------------------
#include <stream.h>

class B1 {
public:
  virtual void x(){ cout << "B1::x()\n"; } // 1
  virtual void y(){ cout << "B1::y()\n"; } // 2
};

class B2 {
public:
  virtual void y(){ cout << "B2::y()\n"; }
  virtual void x(){ cout << "B2::x()\n"; }
};

class D : public B1, public B2 {
public:
  virtual void y(){ cout << "D::y()\n"; }
  virtual void x(){ cout << "D::x()\n"; }
};

void f(D* v) { cout << "f: v->x() "; v->x(); }

main()
{
  D  d;

  cout << "d.x() ";
  d.x();

  f(&d);
}

--------sample output-----------------------------

d.x() D::x()
f: v->x() D::y()

Sherif El-Kassas, elkassas@eb.ele.tue.nl         .       :.
Digital Systems Group, EH 11.29            \_____o__/ __________
Eindhoven University of Technology,               .. /
5600 MB Eindhoven, The Netherlands.                 /