E
Edward Jensen
Hi,
I need to write many instances like the following struct
struct Function191 : public Function {
double operator()(double x) {
return cos(x) - x;
}
friend std:stream& operator<< (std:stream& os, const Function191&
f) {
return os << "cos(x) - x";
}
};
Is there a way to generalize this, such that I can write a generic struct,
which takes a parameter which is both interpreted as code for
operator() and as string for operator<<? I was hoping it would be possible
with templates for example:
Func<"cos(x) - x"> f1;
Func<"exp(x) - log(x)"> f2;
Is this possible?
Best,
Edward
I need to write many instances like the following struct
struct Function191 : public Function {
double operator()(double x) {
return cos(x) - x;
}
friend std:stream& operator<< (std:stream& os, const Function191&
f) {
return os << "cos(x) - x";
}
};
Is there a way to generalize this, such that I can write a generic struct,
which takes a parameter which is both interpreted as code for
operator() and as string for operator<<? I was hoping it would be possible
with templates for example:
Func<"cos(x) - x"> f1;
Func<"exp(x) - log(x)"> f2;
Is this possible?
Best,
Edward