It's polymorphism in action. A method marked as virtual can be overridden by classes inheriting from that method. Basically, if you have a class (like ForgeCommand) that derives from another class (like Command), then you can store pointers to ForgeCommand objects in variables of type (Command *). Let's setup an example:
class Animal {
public:
string speak {
return "This animal can't speak";
}
};
class Cow: public Animal {
public:
string speak {
return "mooo";
}
};
class Bird: public Animal {
public:
string speak {
return "tweet";
}
};
Now let's do some stuff with those classes:
Cow cow;
Bird bird;
Animal * r_cow = &cow;
Animal * r_bird = &bird;
cow.speak(); // "mooo"
bird.speak(); // "tweet"
r_cow->speak(); // "This animal can't speak"
r_bird->speak(); // "This animal can't speak"
Now what do we see here? First of all, we can store a pointer to a Cow object in an (Animal *) variable, namely r_cow. But if we call r_cow->speak(), we see that Animal::speak() happens, because r_cow only knows that it has an Animal. Now let's change the Animal class a bit. More specifically, we'll change "string speak {" to "virtual string speak {". This is an important change, because r_cow->speak() now no longer means "Hey r_cow, use your speak() method on whatever you're currently holding", but "Hey r_cow, make whatever you're holding use its own speak() method". Let's see what happens when we run the above code again:
Cow cow;
Bird bird;
Animal * r_cow = &cow;
Animal * r_bird = &bird;
cow.speak(); // "mooo"
bird.speak(); // "tweet"
r_cow->speak(); // "mooo"
r_bird->speak(); // "tweet"
That's much better, right? Now we can call speak() on any pointer to an Animal, and the animal will call its own speak() method.