




SPHERE.H
Further efficiency can be gained by reducing the number of function calls required.
The inline directive tells the compiler to replace the member function call with the actual function code.
class sphere
{
public:
sphere(void);
~sphere(void);
void copy(const sphere&);
void setRadius(float);
float getRadius(void);
void setPosition(float, float, float);
inline float getXPosition(void) { return xPosition; }
inline float getYPosition(void) { return yPosition; }
inline float getZPosition(void) { return zPosition; }
protected:
float xPosition;
float yPosition;
float zPosition;
private:
void resetPosition(void);
float diameter;
};
SPHERE.CXX
Inline member functions must be defined within the class declaration.
The member function code defined within sphere.cxx is not available for replacement when compiling main.cxx.
#include "sphere.h"
sphere::sphere(void)
{
resetPosition();
diameter = 0.0;
}
sphere::~sphere(void)
{
}
void sphere::copy(const sphere& fromSphere)
{
xPosition = fromSphere.xPosition;
yPosition = fromSphere.yPosition;
zPosition = fromSphere.zPosition;
diameter = fromSphere.diameter;
}
void sphere::setRadius(float value)
{
diameter = value*2.0;
}
float sphere::getRadius(void)
{
return diameter/2.0;
}
void sphere::setPosition(float xValue, float yValue, float zValue)
{
xPosition = xValue;
yPosition = yValue;
zPosition = zValue;
}
void sphere::resetPosition(void)
{
xPosition = 0.0;
yPosition = 0.0;
zPosition = 0.0;
}