When I do this I get this error
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
when calling dutyStack[0]();
. But if I add dutyStack.reserve(10);
or if I only have one element in the vector I do not get the error. I suspect something is going on when it's copying the elements when resizing the vector but I really have no idea.
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
class Class1
{
public:
void duty1(){cout<<"duty1";}
void duty2(){cout<<"duty2";}
};
int _tmain(int argc, _TCHAR* argv[])
{
vector<tr1::function<void()>> dutyStack;
Class1 myclass;
dutyStack.push_back( tr1::bind(&Class1::duty1, myclass) );
dutyStack.push_back( tr1::bind(&Class1::duty2, myclass) );
dutyStack[0]();
dutyStack.erase(dutyStack.begin());
}
I'm under visual studio 2008, Windows 7.