I am trying to make a function of a function using pointers to functions, similar to what is given at the bottom (last section) of this link on www.cplusplus.com, except a little more advanced. I am trying the following:
In myFile.h
// namespace for: Functions
namespace Functions {
// namespace for: 1D functions
namespace OneDimensional {
// Function for: f(x) = x * x, Note: read t as times
double xtx(double x);
}
// namespace for: 2D functions
namespace TwoDimensional {
// Function for: f(x, g(y)) = x + g(y), Note: read _ as "of"
double f_xANDg_y(double x, double(*g)(double y));
}
}
In myFile.cpp
double Functions::OneDimensional::xtx(double x) {
return (x * x);
}
double Functions::TwoDimensional::f_xANDg_y(double x, double(*g)(double y)) {
return (x + (*g)(y)); // <== This is where I get the Error (E0020)
}
I checked the error E0020 and this brought me to Stack Overflow and that user was missing a brace. I checked and I have no missing brace (but I could be wrong even after checking a few times).
Is it that I am implementing this idea of f(x, g(y)) incorrectly, or am I actually missing a brace?
y? Which value do you want to pass tog? Did you mean to passyas an extra parameter? It's difficult to tell what you are trying to achieve, but perhaps something likedouble f_xANDg_y(double x, double y, double(*g)(double)) { return x + g(y); }I don't see the point of the exercise though.