I want to make a function f() that uses three values to compute its result: a, b, and e. e is dependent on a and b, so technically f() is only a function of a and b. But for the sake of readability, it is easier to look at a function containing the abstraction e than to look at a messier formula containing many a's and b's.
Is there any way to use dependent variables like e without the use of nested functions, which C++ does not allow?
C++ does have local variables, which makes this easy:
double f(double const a, double const b)
{
double const e = a * b + b * b * b;
return a + b + e;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With