メンバーをバインドして、クラス インスタンスの外部に関数オブジェクトを格納したいと考えています。ただし、VS2012 では、これは までしか機能せずplaceholders::_4
、エラーでポップアップし始めます。たとえば、次のようにします。
#include <iostream>
#include <functional>
using namespace std;
using namespace std::placeholders;
class A
{
public:
int method(int a,int b,int c,int d,int e)
{
return a;
}
};
int main()
{
std::function<int (int,int,int,int,int)> obj;
A a;
// error: no instance of overloaded function "std::bind" matches the argument list
obj = std::bind(&A::method,&a,_1,_2,_3,_4,_5);
std::cout << obj(1,2,3,4,5);
return 0;
}
上記のコードは GCC 4.7.2 では正常にコンパイルされますが、Visual Studio 2012 では上記のエラーが発生します。