This is the mail archive of the gcc-bugs@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: g++: virtual function call failes in constructor


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

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