I hava a class declaration with a code snippet that I don't understand:
class Weapon { public: virtual void attack() const = 0; };
What does the part mean const = 0?
const = 0
This is a pure virtual method ( =0) that should not modify the data of the class ( const). You must provide implementation in one of the classes originating from Weapon! See So: The Difference Between a Virtual Function and a Pure Virtual Function
=0
const
Weapon
It is expected that you will receive specific classes Weapon(can be considered an interface), such as Axe, Shotgunetc., where you provide a method attack().
Axe
Shotgun
attack()
const , - , ( mutable ). , , , .
mutable
= 0 const. virtual, , . , . , , abstract, .
= 0
virtual
, Weapon, attack() . , :
class Sword : public Weapon { public: void attack() const { // do something... } };