test…
27 Wednesday Nov 2013
Posted Uncategorized
in27 Wednesday Nov 2013
Posted Uncategorized
in14 Thursday Nov 2013
Posted c++
inTags
c++, constructor, java, yahoo
#include using namespace std; struct A { A() { x(); } virtual void x() { cout<<"A"<<endl; } }; struct B: public A { B() { x(); } void x() { cout<<"B"<x(); }
c++ result
A
B
A
B
B
java result:
B
B
B
B
B
reason:
while c++ constructor is called, object of class is not instanced yet and doesn’t know what class itself is, no virtual table.
java is different. virtual table is already there.