Base
doesn't have method bar()
, only L3
(and its derived class) has.
So you can't call bar()
from Base
.
You may do the following:
Base* base = List.curr();
L3* l3 = dynamic_cast<L3*>(base); // l3 is non null if base is non null and IS a L3.
if (l3 != nullptr) {
// base->bar(); // ILLEGAL
l3->bar();
}
In the case you know that Base
IS a L3
you may use a static_cast
:
NewA newA;
Base* base = &newA;
L3* l3 = static_cast<L3*>(base);
newA.bar();
// base->bar(); // ILLEGAL
l3->bar();