The execution of program stops on windows seven abruptly..whats the error..!!
Hi!
I am new to C++ programming and was tinkering around with a program to learn about function pointers. I wrote the following code (using borland c++ compiler). The program compiles without error or warning but when I run the exe file it aborts..error message pops up on windows 7 saying execution of program has stopped working...
Below is the code..can someone tell me what have I done wrong..I am unable to figure out .. :(
Code:
#include <iostream>
float* Plus(float num1, float num2) {float* res; *res = num1 + num2; return res;}
typedef float*(*pFunc)(float, float);
pFunc GetPointer(char c)
{
if(c == '+')
return &Plus;
else if(c == '-')
return &Plus;
else
return &Plus;
}
float Calc(float num1, float num2, float* (*pCalcMethod)(float, float))
{
float x=23;
std::cout<< "result inside Calc method" << *pCalcMethod(num1, num2) << std::endl;
return x;
}
int main()
{
float result = Calc(50, 25, &Plus);
std::cout << "Result: " << result << std::endl;
system("PAUSE");
return 0;
}