This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36911] New: Virtual function problem
- From: "david dot golub at yale dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jul 2008 17:42:42 -0000
- Subject: [Bug c++/36911] New: Virtual function problem
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When a virtual function is called from a base class constructor, it always
calls the base class's version of the function, even if a derived class
overrides it. Example code:
#include <iostream>
using namespace std;
class Base {
public:
Base();
virtual void overridable();
};
class Derived : public Base {
public:
virtual void overridable();
};
void Base::overridable() {
cout << "Base::overridable called" << endl;
}
Base::Base() {
overridable();
}
void Derived::overridable() {
cout << "Derived::overridable called" << endl;
}
int main() {
Derived obj;
return 0;
}
Output: Base::overridable called
Should be: Derived::overridable called
--
Summary: Virtual function problem
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: david dot golub at yale dot edu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36911