Jump to content
  • Advertisement
Sign in to follow this  

Problem with vectors while compiling int VC++

This topic is 2415 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()

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?

Share this post

Link to post
Share on other sites
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!