Quote Originally Posted by grumpy View Post
As an example, inside your Calc function, you might do this
Code:
float* Calc(float num1, float num2, char c)

{
    pFunc pFuncRes =GetPointer(c);   // simpler way of getting the pointer
    
    float *resultF = pFuncRes(num1, num2);     // store the returned pointer
    float returnvalue = *resultF;    // store the value pointed to
    delete resultF;                        //  release the allocated memory
    return returnvalue;    
}
Anyway, the best thing you could do is change the return values of your functions from float * to float. Just because you CAN return a pointer, doesn't mean it's a good idea. As exhibited by the hoops jumped through in my example to make things work right.

It is a moderately common Java technique to dynamically allocate a value, and later forget about it. This works in Java for a number of reasons (eg garbage collection, semantics of "what is a variable") but such techniques are really bad karma in C++.
Thank you Grumpy for the help..I wrote this code mainly to get a feel of function pointers..so just asking doubts to clarify things
If i use the code like u suggest..then return type of Calc should be made float not float*..right??
Also just one more thing..if u have seen my earlier posts..why is it that when I didn't initialize res in Plus the program aborted..but in the second or third post (inside the Calc method) when I use the resultF without initialising it works..!!
Thanks for the help again..