Jump to content
  • Advertisement
Sign in to follow this  
ak09

Problem with vectors while compiling int VC++

This topic is 2237 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!