V konstruktoru předka nelze objekt "downcastnout" na potomka, objekt se chová jako instance předka.
Z working draft (N4861,
https://timsong-cpp.github.io/cppwp/n4861/class.cdtor):
The typeid operator ([expr.typeid]) can be used during construction or destruction ([class.base.init]).
When typeid is used in a constructor (including the mem-initializer or default member initializer ([class.mem]) for a non-static data member) or in a destructor, or used in a function called (directly or indirectly) from a constructor or destructor, if the operand of typeid refers to the object under construction or destruction, typeid yields the std::type_info object representing the constructor or destructor's class.
If the operand of typeid refers to the object under construction or destruction and the static type of the operand is neither the constructor or destructor's class nor one of its bases, the behavior is undefined.
Ze stejného důvodu v té druhé ukázce ten
dynamic_cast "selže" a hodnota proměnné derived je
nullptr.
Co třeba pro vytváření objektu místo přímo
make_shared použít nějakou vlastní podobnou funkci, která nejdříve objekt vytvoří, a pak buď přímo provede ten výpis nebo teda zavolá tu virtuální metodu na tom hotovém objektu.