c++ - Calling a function without explicitly refering to it that changes according to input -


I am trying to create a speed distance and time calculator which is as efficient as possible and calls to a function Want to mention the use of an indicator that changes according to the input, but I'm not sure how to do this. I have tried many different things:

My best effort:

  // inside class math double capsapend (double distance, double time); // These functions return the double value of the formula (non-stationary) double-calc distance (double speed, double time); Double calcium (double speed, double distance); // Inside the main typedef double (Math :: * FuncChosen) (double first, double second); FuncChosen p = & amp; Math :: CalcSpeed; // It changes with the same parameter type and return type P (1, 2) in the mathematical class according to the input in various functions; // Not a function, how can I clearly not call the function?  

Is there any way to make this function explicitly without using pointers or otherwise making calls without it. According to the input, will the switch from the indicator call the function? I do not know exactly where and what I try to start is illegal. I basically want to select the function on runtime without using many IOS and thus to avoid recurrence (I People with similar problems have found, but for my purpose, there is no efficient way to do this.)

Thanks in advance,

And, yes, I am new C ++ and pointers With / reference and memory is not a lot.

Edit: For context, Finish, Complete after compilable

You have not included any, but the comments and code indicate that there are non-static member functions inside the function, class math . Type FuncChosen is a pointer for the member function.

Indicators are strange creatures to members, it is not really an indicator, because it does not directly point to anything, think of an indicator as a member in the class as "identifier" . Therefore, p recognizes a particular member function (such as calcpepe ). As you usually call the member function by calling on an object, you need to supply the object to call the point through the member. Therefore, for example, if you have this code:

  math m; Double res = m.calcSpeed ​​(1.0, 2.0);  

Then the pointer-to-member will be equal to p :

  Math m; FuncChosen p = & amp; Math :: CalcSpeed; (Mp) (1.0, 2.0);  

operator . * (and related -> * ) is used for an indicator for a member.


For completeness: The above non-static member functions are applicable if there are stable member functions instead of calcspeed etc. You use normal pointers to refer them.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -