double ClassName::FunctionName1(void) const{
double C = alpha*beta;
/* do something */
return VariableName2;
}
double ClassName::FunctionName2(void) const{
double C = alpha*beta;
/* do something different */
return VariableName2;
}
double ClassName::FunctionName3(void) const{
double C = alpha*beta;
/* do something very different */
return VariableName3;
}
Both alpha and beta are static variables of class ClassName specified right at the beginning when the program is executed. Each function is called millions of time, and so I was wondering is there any way that I can avoid doing this multiplication every time these functions are called?
I don't want to declare C as a static member of ClassName.
I'm assuming alpha and beta can change between FunctionName calls (ie they're nonconstant)
I don't want to declare C as a static member of ClassName.
That's the best way to do it.
You have two options:
1) do the multiplication every time
or
2) have a variable remember the result of the multiplication. That variable's lifetime will obviously need to be longer than the functions (ie: needs to be global/class scope).