std:bindにメンバー関数を扱う

メモメモ

#include <iostream>
#include <functional>

class Foo {
public:
	Foo():m_val(0){}
	~Foo(){}
	void setVal(int val){m_val=val;}
	int getVal(void){return m_val;}
private:
	int m_val;
};

void main()
{
	Foo foo;
	auto func = std::bind(&Foo::setVal,&foo,10); // setVal(10)をbind
	std::cout << foo.getVal() << std::endl;
	func();
	std::cout << foo.getVal() << std::endl;
}

出力

0
10

いろんな試してみよう