Topic: Question about multiple inheritance ...


Author: jsun@ncsa.uiuc.edu (Jun Sun)
Date: 3 Sep 1993 04:19:32 GMT
Raw View
I met this problem in a large simulation system.  I will really appreciate
if some expert can give some hints.

In the program, I have following class structure :

// ------------- start of class definition --------------------------
Class A
{
...

public :

virtual void work();

}

Class A1 : public A
{
...  // no declaration about work
}

Class A2 : public A1
{
...  // no declaration about work
}

Class B
{
...

public :

virtual void work();
}

Class Child_Class : public A2, public B
{

public :

void work();
}

// --------------- end of class definition ----------------------

And  somewhere in the program there is a function,

// --------------- a function --------------------
int func()
{
B *pointer;

pointer = new Child_Class;

...

pointer -> work();

...

}

// ------------  end of functio --------------------

The compilation is ok.  The problem seems to be that whenever "pointer->
work()" gets called, instead of "work()" defined in Child_Class is called,
some irrelavent function defined in A is executed.  This suggests me
the virtual function table is got messed up. (not sure)

I'm using gnu compiler g++ on Sun Sparc.

--


JJJJJJJJJJJJJJJ  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
      JJ  Jun Sun
      JJ  jsun@ncsa.uiuc.edu
      JJ
JJ   JJ    "Don't worry.  Be happy."         =>        ^  ^
  JJJ                                                   \/
======================================================================