Possible Duplicate:
What's the point of OOP?
What are the advantages of using object-orientated programming over function-orientated.
As a trivial example consider:
struct vector_t {
int x, y, z;
}
void setVector(vector_t *vector, int _x, int _y, it _z) {
vector->x = _x;
vector->y = _y;
vector->z = _z;
}
vector_t addVector(vector_t* vec1, vector_t* vec2) {
vector_t vec3;
vec3.x = vec1->x + vec2->x;
// and so on...
return vec3;
}
Now, I am not incredibly familiar with object-orientated programming, but the above would translate to OOP as:
class vector_t {
private:
int x, y, z;
public:
void set(int _x, int _y, int _z) { ... };
int getX() { return x; }
// ...
void addVector(vector_t *vec) { ... };
// ...
};
My question is this? What really makes the second code example so prefered over the first in modern programming? What are the advantages and disadvantages?