深入探索指针与UML:从赛马程序谈起
1. 赛马程序代码解析
1.1 类的定义
首先,我们来看赛马程序中涉及的两个主要类: horse
和 track
。
class horse
{
private:
float finish_time; // this horse’s finish time
float distance_run; // distance run so far
public: // create the horse
horse(const int n, const track* ptrT) :
horse_number(n), ptrTrack(ptrT),
distance_run(0.0) // haven’t moved yet
{ }
~horse() // destroy the horse
{ /*empty*/ } // display the horse
void display_horse(const float elapsed_time);
}; // end class horse
class track
{
private:
horse* hArray[maxHorses]; // array of ptrs-to-horses
i