About the following code:
class A {
A * next;
static A* tmp;
public:
A() : next(tmp) {
if (tmp)
tmp->next = this;
tmp = this;
}
virtual void print() {
if (next)
next->print();
}
};
class B : public A {
int a = 1;
public:
void print() {
cout << "foo";
A::print();
}
};
A* A::tmp;
int main(){
B c;
B b;
b.print();
}
Why does next->print();
leads to B::print()
and not back to A::print()
? Since next
is a static pointer of A
why does it go to B
's function?
EDIT: added B c;
that I removed accidentally when posting.