Tag Info

New answers tagged

1

While a non-capturing lambda function can be converted into a free function pointer, a capturing one can not, which you've discovered. The generic approach to using member functions as callbacks is a common problem and is typically resolved via thunking or trampolines. In short, you make a static/free function which compatible with the mandated interface, ...


1

I think it is perfectly fine use inheritance if your only plan on having 3 or so subclasses. AttackSpaceship, ResearchSpaceship, ReligiousSpaceship would be fine, but what if six months from now you decide to add 3 more types of ships? What a hassle it would be having to create another class for each new type of ship. Other worse extensibility problems might ...


5

Prefer composition over inheritance as it is more malleable / easy to modify later, but do not use a compose-always approach. class Weapon { public: virtual ~Weapon() = default; virtual void action() = 0; }; class AttackWeapon : public Weapon { public: void action() override { // ... } }; class ...



Top 50 recent answers are included