I'm trying to pass simple functions to a specific vector and after using them with their indexes. I'm doing good when compiling my code in Dev-C++.
#include <vector>
#include <iostream>
using namespace std;
typedef int (*funcs)(int, int);
vector<funcs> functions;
int sum(int a, int b){return a + b;}
int sub(int a, int b){return a - b;}
int main()
{
functions.push_back(sum);
functions.push_back(sub);
cout << functions[0](5, 4) << endl;
cout << functions[1](5, 4) << endl;
return 0;
}
The output shows as 9 and 1, for this case.
However, the same code compiled in VC++ 2008 gives me an Access violation reading location while trying to acess the functions by the vector.
Should I link or include something to avoid this from occurring?
Thanks