




BALL.H
We can create a subclass of the class sphere that inherits all of the member variables and member functions of the parent class.
We include the sphere.h file because the sphere class must be declared before a child class can be declared.
#include "sphere.h"
class ball :public sphere
{
public:
ball(void);
~ball(void);
void setVelocity(float, float, float);
inline float getXVelocity(void) { return xVelocity; }
inline float getYVelocity(void) { return yVelocity; }
inline float getZVelocity(void) { return zVelocity; }
protected:
float xVelocity;
float yVelocity;
float zVelocity;
private:
void resetVelocity(void);
};
BALL.H
The constructor for sphere is called automatically before the constructor for ball.
Therefore, we do not need to initalize the part of the class that is inherited.
include "ball.h"
ball::ball(void)
{
resetVelocity();
}
ball::~ball(void)
{
}
void ball::resetVelocity(void)
{
xVelocity = 0.0;
yVelocity = 0.0;
zVelocity = 0.0;
}
void ball::setVelocity(float xValue, float yValue, float zValue)
{
xVelocity = xValue;
yVelocity = yValue;
zVelocity = zValue;
}