It is not clear what kind of problems you are talking about.
As has been said more than once, the mechanism for invoking virtual methods in constructors works as if the dynamic type of an object is determined by the constructor that is currently working. In all other respects, the virtual mechanism works as usual.
In your example, in accordance with this rule, during the operation of the constructor of class B
from the point of view of the virtual mechanism, the constructed object will be of type B
Accordingly, the virtual call of the method f
from the constructor B::B
falls into the implementation of B::f
.
There are no problems here.
In such a trivial example as yours, most compilers immediately "guess" that it is the B::f
method that will be called and optimize the virtual call, replacing it with the usual direct call. In more tricky cases (such as a call through a pointer), the call will remain virtual, but it will still work correctly (considering the above).
Cm.
Calling a virtual method in the constructor
Strange and incomprehensible mistake
B::f();
. - freim