#include "CvTeam.h"
class CvTeamAI : public CvTeam
{
(...)
public:
(...)
void AI_doTurnPost();
(...)
};
I'm wondering which implementation of AI_doTurnPost() will execute in both the calls that are shown here... I presume that the one in CvTeam.cpp will use the definition provided by CvTeamAI.cpp (please correct me if I'm wrong), but what about the call made in CvPlayer.cpp? Will it use the definition that's in CvPlayerAI.cpp, or will just return 0 like it says in CvPlayer.h? And in both CvPlayer.h and CvTeam.h, what does the keyword virtual does there?
Thank you in advance,
AeonFlux1212
by the way I tried to be as accurate as possible with the includes on top of each block of code, in case it's relevent to the question...
Both CvPlayer::AI_doTurnPost and CvTeam::AI_doTurnPost are pure virtual functions. This means they do NOT have an implementation in their respective base classes. The =0 is what indicates a pure virtual function. The notation does not mean the function returns 0. In fact, it can't since it's a void function.
You can't instantiate Shape directly since it's an abstract class. But you can derive Square and Circle from it, both of which implement area(). Now if I have a pointer to some object derviced from Shape, I can call shape->area() and the appropriate function will be called.
I see that in CvTeam.h and in CvPlayer.h the functions are defined as virtual, but in classes CvTeamAI and CvPlayerAI they're not... and that the definitions provided by CvTeamAI.cpp and CvPlayerAI.cpp are not the same :
In this case I presume that the one from CvPlayerAI will be used in the CvPlayer.cpp call and the one from CvTeamAI will be use in the CvTeam.cpp call... is that right?
The CvTeam and CvPlayer inheritance trees are unrelated. You just happen to have two classes (four if you count the abstract base classes) that have a function with the same name. This isn't a problem since the function name is qualified by the class it occurs in.