




SPHERE.H
Furthermore, we can now separate the class declaration and definition of member functions into two files.
The sphere.h file holds the class declaration while sphere.cxx contains the member function definitions.
class sphere
{
public:
sphere(void);
~sphere(void);
void setRadius(float);
float getRadius(void);
protected:
float xPosition;
float yPosition;
float zPosition;
private:
void resetPosition(void);
float diameter;
};
SPHERE.CXX
We include the sphere.h file here because member functions cannot be defined before a class is declared.
#include "sphere.h"
sphere::sphere(void)
{
resetPosition();
diameter = 0.0;
}
sphere::~sphere(void)
{
}
void sphere::setRadius(float value)
{
diameter = value*2.0;
}
float sphere::getRadius(void)
{
return diameter/2.0;
}
void sphere::resetPosition(void)
{
xPosition = 0.0;
yPosition = 0.0;
zPosition = 0.0;
}