Code:
c.arr.at(0).f(); // this should be D1::f, not B::f
Well since C has a vector<B> member it will print the "overload" for B, not D1, remember C doesn't inherit anything from B.
Perhaps you meant something more like:
Code:
...
class C {
public : std::vector<B*>arr;
};
int main()
{
B b;
D1 d1;
D2 d2;
C c;
c.arr.push_back(&d1);
c.arr.push_back(&d2);
b.f();
d1.f();
d2.f();
c.arr[0]->f(); // this should be D1::f, not B::f
return 0;
}
By the way your first code would probably do what you wanted if you changed the function to something like:
Code:
template <typename Defender>
void DisableRandomWeapon(Defender &d)
{
d.Loadout.at(Pick(rng, d.Loadout.size())).disabled = true;
}