Well this is more of a question on Programming style ,I think....
In every example Of OO (with classes and what not) Programming I see with C++, i've noticed a trend. The class functions(methods?) were always written outside of the class definition. I don't know why but this irks me to no end. Is there anything in particular that is wrong with writing all of the class methods within the class itself? This just makes more sense to me and annoys me less.
It's the one thing, visually, that i like better about Java than C++
For example:
Why is it like this:
Code:
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area ();
};
void CRectangle::set_values (int a, int b) {
x = a;
y = b;
}
int CRectangle::area(){
return (x*y);
}
int main () {
CRectangle rect, rectb;
rect.set_values (3,4);
rectb.set_values (5,6);
return 0;
}
Instead of this:
Code:
class CRectangle {
int x, y;
public:
void set_values (int,int){
x = a;
y = b;
}
int area (){
return (x*y);
}
};
int main () {
CRectangle rect, rectb;
rect.set_values (3,4);
rectb.set_values (5,6);
return 0;
}
The former(first one) Just seems to create more clutter.
Basically i'm asking, are there any specific reasons it is done this way?
If there are, are the reasons coding style, organization of some sort, or some practical reason that i haven't noticed.
This question applies to the constructor/deconstructors as well as the methods
Thanks for your answers. If i get any.
