This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++: virtual function call failes in constructor
- To: Martin Weber <weberm at physik dot rwth-aachen dot de>
- Subject: Re: g++: virtual function call failes in constructor
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- Date: 23 Jan 2001 17:14:44 +0100
- Cc: gcc-bugs at gcc dot gnu dot org
- Organization: CodeSourcery, LLC
- References: <Pine.LNX.4.10.10101231153450.14508-101000@axpclmg.physik.rwth-aachen.de>
Martin Weber <weberm@physik.rwth-aachen.de> writes:
[...]
| Description:
|
| The call to the virtual function Print() in A::A() is not resolved to
| B::Print() in the statement B b; as it is expected for a virtual function.
| The output of the program is expected to be
This is not a compiler bug, but a misunderstanding of C++ rules.
The code generated by the compiler is correct. In constructors, the
dynamic type of an object is its static type so sa->Print() should be
resolved to sa->A::Print(), which g++ does.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com