The following code is late binding test() method but shouldn't it bind early? because test() method is not virtual in class B(but in class A), and we are using pointer of class B.
class A{
public:
virtual void test(){
cout<<"test a";
}
};
class B : public A{
public:
void test(){
cout<<"Test b";
}
};
class C: public B{
public:
void test(){
cout<<"test c";
}
};
int main(){
B *bp;
C objc;
bp = &objc;
bp->test(); // test c
}
test
is virtual in all classes here; thevirtual
keyword does not need to be repeated. – Hoop