And I am wondering if my code is good, even if it violates this rule:
It depends on what you mean by "fine." Your program is well-formed, and its behavior is clearly defined, so it will not cause undefined behavior and the like.
However, when viewing a call to a virtual function, you can expect that the call is resolved by calling the implementation provided by the most derived type that overrides this function.
Except that during construction, the corresponding sub-object has not yet been built, so the most derived subobject is the one that is currently being built. Result: the call is sent as if the function were not virtual.
This is against intuition, and your program should not rely on this behavior. Therefore, as a competent programmer, you should get used to avoiding such a pattern and following the guidance of Scott Meyer.
source share