This is the mail archive of the gcc@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]
Other format: [Raw text]

Re: Problem with using new libs with old app (without relink)


> We started to make a library, and found a
> problem(?), there is an example:
> 
> class A {
> public:
>   A();
>   virtual void b();
> };
> class B: public A {
> public:
>   B();
>   virtual void d();
> };
> 
> , in test we call dynamic_cast<B*>(test)->d();
> 
> if we switch to a newer lib (without relinking
> test program) in which added 'virtual void c()'
> into class A, we get 'A::c()' executed instead
> of 'B::d()'.

The reason you are seeing this is because the virtual function table for
class B first lists the virtual functions inherited from class A, and then
adds the new virtual functions added in class B.  By adding a function,
you've moved A::c into the slot formerly executed by B::d.  Your test
program that you did not relink refers to class B, and any calls to B::d
are translated by the compiler into "call the function using the second
virtual function table slot".

> We understand, that it is not a bug in common
> meaning, but could you help us with advise
> haw to make it work (other then relink - this
> must not be done due to specific of our project).

Sorry, you're asking for the impossible.  The very fact that you ask
suggests a fundamental misunderstanding about how virtual functions
work.


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