My question is simple, i have probably missed something essential about functions but i cant find an explanation to it anywhere so im posting it here: how come void set_values (int,int); is missing names for its variables? shouldn't it be like void set_values (int x,int y);. can anyone explain how this works?
1 2 3 4 5 6
class CRectangle {
int x, y;
public:
void set_values (int,int);
int area (void);
} rect;
You can supply names for the arguments in function declarations, but they are ignored by the compiler. I find it a good practice to do so. It serves as a reminder of what each argument is for so when using the class I only have to refer to the header and not the full .cpp file.
The function declarations serve to tell the compiler the type and number of arguments each function will accept. This information is needed by the compiler when the function is called from somewhere. Only when you define the function are the argument names needed. The scope of argument names is local to the implementation.