This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: static_cast + virtual table = problems ?
- To: ulisses at watson dot ibm dot com
- Subject: Re: static_cast + virtual table = problems ?
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Wed, 8 Sep 1999 09:04:46 +0200
- CC: gcc at gcc dot gnu dot org
- References: <Pine.A32.3.93.990907200518.27690E-100000@jacare.watson.ibm.com>
> 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