This solution is inspired by @dyp's comment:
You can separate two duties B, namely: "provides B-style implementation " and "can be created".
class B_for_implementation : public A
{
void doSpecificStuff();
};
class B_for_objects final : public B_for_implementation
{
int f() override {return 5;}
};
class C final : public B_for_implementation
{
int f() override {return 171;}
};
Autonomous objects will be created from B_for_objects, while other classes will be obtained from B_for_implementation.