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]

Re: static_cast + virtual table = problems ?


> a=1
> b=2  <-- why b is being printed ???
> 
> a=1
> 
> If print() is declarad as non-virtual it produces the correct result.

You get the correct result in both cases :-) A static cast is just
that: it changes the static type of some expression. 

It does not make virtual functions non-virtual, so if you invoke a
virtual function on an A&, and the dynamic object is a B instance, you
get the B method.

To always invoke the A method, you have to write

  ba.A::print();

instead.

Hope this helps,
Martin


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