I am trying to define a type for function pointers, in c++. However, once I define the pointer funcp
as a fptr
, I cannot redefine the pointer as a different function, times
. This program does not even compile. Is this because I have to delete the nullptr
before reassigning times
to funcp
?
My code:
#include <iostream>
using namespace std;
typedef int (*fptr)(int, int);
int times(int x, int y)
{
return x*y;
}
fptr funcp = nullptr;
funcp = times;
int main()
{
return 0;
}