In this case you want to use virtual functions on the base class like so:
class Entity // base class
{
virtual void ai(Entity n){}
}
Even though this is just example code, I can see that it might cause problems because you are passing by value instead of myby reference.