Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!ucbvax!SIRIUS.RISC.COM!ckl From: ckl@SIRIUS.RISC.COM (Carl K. Lim) Newsgroups: comp.lang.c++ Subject: problem with virtual function Message-ID: <9008201757.AA23899@sirius.risc.com> Date: 20 Aug 90 17:57:21 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 30 Hello. I have this problem: when I'm calling a virtual function from a parent class's constructor, it fails to execute the derived class's function. For example, in the following program, when B is declared, print() is called from A's constructor. But instead of looking up the B::print(), A::print() is called instead. Has anybody run into this kind of problem? Is there a way to get around it? #include class A { public: A() { print(); } virtual void print() { printf("A\n"); } }; class B : public A { public: B() {} void print() { printf("B\n"); } }; int main() { B b; }