I am trying to create a speed distance and time calculator that is as efficient as possible and would like to refer to call a function using a pointer that changes according to input but am not sure how to do so. I have tried many different things:
My best attempt:
// Inside class Math
double calcSpeed(double distance, double time); // These functions return a double value of the formula (non static)
double calcDistance(double speed, double time);
double calcTime(double speed, double distance);
// Inside Main
typedef double (Math::*FuncChosen)(double first, double second);
FuncChosen p = &Math::calcSpeed; // This changes according to input to different functions in Math class with same parameter types and return types
p(1, 2); // Not a function, how can I non explicitly call the function?
Is there a way to call this function without explicitly referring to it using pointers or otherwise. Like calling a function from a pointer that changes according to input? I don't really know where to start and what to use as everything I try is illegal. I basically want to chose the function at runtime without using several ifs and thus avoiding repetition. (I have found people with similar problems but haven't found an efficient way of doing it for my purpose.)
Thanks in advance,
And, yes, I am new to C++ and haven't done much with pointers/references and memory.
Edit: For reference, the finished, complete code after corrections - compilable