I have a little C++ background but am just getting into the object oriented programming facet of the language. I was reading the C++ Tutorials website about class formatting. I read that it is possible to declare a function within a class then define it outside the class using the scope operator, :: . Given my little experience, I was wondering if it is widely preferred that the function be defined within the class, or preferred if it be defined outside the class, or if it really does not matter.
From C++ Tutorials website
// classes example
#include <iostream>
using namespace std;
class Rectangle {
int width, height;
public:
void set_values (int,int);
int area() {return width*height;}
};
void Rectangle::set_values (int x, int y) {
width = x;
height = y;
}
Meaning, wouldn't it be more compact and efficient to just include the set_values definition within the class?
As always, thanks.