std::function

#include <functional>
#include <iostream>
using namespace std;

// 関数オブジェクトを定義
class Func{
public:
	int operator()()
	{
		cout << "class str!" << endl;
		return 1;
	}
};

// 関数を定義
int str()
{
	cout << "func str!" << endl;
	return 2;
}

int main(){
	function<int ()> func_A;
	function<int ()> func_B;
	function<int ()> func_C;

	func_A = str;   // 関数ポインタを渡す
	func_B = Func();// 関数オブジェクトを渡す
	func_C = []()->int
	{
		cout << "lambda str!" << endl;
		return 3;
	};

	int a = func_A();
	int b = func_B();
	int c = func_C();

	cout << a << ":" << b<< ":" << c << endl;

	return 0;
}

実行結果:

func str!
class str!
lambda str!
2:1:3

動いたwwwww
きめぇwwwwww
ラムダ式含めて色々と試していきたい現実逃避Days