• Advertisement
Sign in to follow this  

Problem with vectors while compiling int VC++

This topic is 2139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Edit: The topic can be deleted, sorry.

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

Share this post


Link to post
Share on other sites
Advertisement
I ran the code in Visual Studio 2010 and it ran fine. I dont see any error with the code. Is it lines

Does it throw errors when reaching both functons[0] and functions[1] ??

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement