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