voidtest_use_function() { FuncContainer container; container.Push([](int x, int y) { return x + y; }); container.Push(FuncB); container.Push(FuncC()); auto afunc = container.Take(0); auto bfunc = container.Take(1); auto cfunc = container.Take(2); cout << "a = " << afunc(3, 4) << endl; cout << "b = " << bfunc(30, 40) << endl; cout << "c = " << cfunc(30, 4) << endl; }
测试结果
using void Push(funcType&& func) using void Push(funcType&& func) using void Push(funcType&& func) using funcType& Take(int index) using funcType& Take(int index) using funcType& Take(int index) a = 7 b = 70 c = 34