Read tip-casting , this is a very simple and important aspect of the language.
In short, you can always refer a pointer to a base to a pointer to a derivative, and then refer to its unique public members.
A * arr[5]; arr[0] = new B; char test = static_cast<B*>(arr[0])->bar;
However, the last line above is a valid statement, even if this A* does not point to an object of type B If you try this on a C object, it will compile and lead to undefined behavior at runtime.
It should be noted, however, that, as a rule, when a person cannot be sure of the type of object to which he refers, a better program design could prevent him from the very beginning. The general statement says that this is true for type typing in general.
PS Please note that in your code, bar is a private member of class B (unintentionally, I assume that any class member is private by default), so it cannot be accessed in any case outside of the implementation of class B
source share