In C++, I'm trying to decide whether or not to use a struct or class. So far I understand that both are more or less identical, but a class is used more often when private variables are needed or to group the concept of an object that performs actions.
But what I'm wondering is: Does including functions within a class increase the memory requirements (as opposed to having structs, with functions separated)?
Here is an example
class Vector2D {
public:
int x;
int y;
Vector2D();
getMagnitude();
Normalize();
}
vs.
struct Vector2D {
int x;
int y;
}
// Some functions defined separately
getMagnitude(Vector2D v);
Normalize(Vector2D v);
And if I have a bunch of other vector functions, say, adding two of them together and I have a vector class, is it better if those are included in the class, so you have a function like addToVector(Vector2D v2) or to keep these multi vector functions outside of the class so that you'd have an addToVector(Vector2D v, Vector2D v2)?
I understand the second question might lean towards opinion, but if there is a "best practice" defined way, I'd like to know.
Thank you