I have the following class and thought that when I call the set command to set a member, I always use value. Would that be fine?
class ModMisfit {
protected:
Real dtau;
Real mdacc;
Real mindist;
bool hw;
Source** src;
public:
void set_integration(
const Integration value);
void set_dtau(
const Real value);
void set_mdacc(
const Real value);
void set_mindist(
const Real value);
void set_hw(
const bool value);
};
void ModMisfit::set_dtau(
const Real value) {
for ( int i = 0; i < nsrcs; i++ ) {
src->SetdTau( value );
}
}
inline void ModMisfit::set_mdacc(
const Real value ) {
mdacc = value;
}
inline void ModMisfit::set_mindist(
const Real value ) {
mindist = value;
}
void ModMisfit::set_integration(
const Integration value ) {
for ( int i = 0; i < nsrcs; i++ ) {
Src->SetIntegration( value );
}
}
You can call the functions, variables, and parameters whatever you want, as long as they don't overlap. They can't be all the same because, at best, some won't be available to you inside the function, at worst you'll get compiler errors in some contexts.
Beyond that I still have no idea what you're asking.
I have a member function called mdacc (look at the green variable) , and in the setter function I am using mdacc for the input argument. And in the program, the user specifies mdacc as well, that then sets the class value for mdacc.
I used to have the class member starting with capital letter, whereas all the others are lower case. But left me with some confusion . What do people code in such cases?
class ModMisfit {
protected:
Real mdacc;
public:
void set_mdacc(
const Real mdacc);
};
Like I said, it will make the real variable unavailable inside that function. You could access them with classname::varname, maybe. Still, not a good idea to overlap them like that.