Hello,
I noticed that in c++ everything that can be done using a static function in a class could be done by using a public function in the same namespace. Assuming that you bind your classes in a namespace these functions do not take up names in the global namespace. As such I was wondering when to use static functions in classes and when to use public functions. For an example here is the current situation where I cannot decide which to use:
class Sprite
{// private:
//Some image data
public:
//some functions
Sprite &applyPoints(vector<Coord2D> ps,Colour c);//applies the given colour to a set of points
//Now I want to make it easy to draw bresenham lines without writing the algorithm yourself:
#ifdef STATIC_VERSION
static vector<Coord2D> getLineCoords(Coord2D start,Coord2D end);
#else
vector<Coord2D> getLineCoords(Coord2D start,Coord2D end);
#endif
When, if ever, is it appropriate to use the static version and when, if ever, is it appropriate to use the public version?