So a pretty simple question, but I can't seem to find a general rule of choosing one over the other in some cases.
Let's say I have a simple Point
class, like this:
class Point
{
public:
Point();
Point(double, double, double);
Point(const Point& other);
Point& operator=(const Point& other);
bool operator==(Point& lhs, Point& rhs);
void translate(double, double, double);
double getX() const;
double getY() const;
double getZ() const;
void setX(const double);
void setY(const double);
void setZ(const double);
private:
double x_, y_, z_;
}
All well, but why not make it a struct with public x, y, z and save half of the code?
Another example lets say I have a Header
struct like this:
struct Header
{
short int id;
short int version;
size_t indexOffset;
size_t indexSize;
}
Under what circumstances I'd want to make it a class? Also is there any difference between the above and something I've also seen in a quality code like this:
class Header
{
public:
short int id;
short int version;
size_t indexOffset;
size_t indexSize;
}
So I guess a sub-question to this is how do I decide when to make member variables private. I know OO purists will probably say always, but I'm not sure about the benefit.
Many thanks.