#如我写了几个函数,我要把他放到一个列表里,在搞另一个列表储存当用户打出这个文字时我可以触发对应的函数#
代码如下:
#include <iostream>
#include <list>
#include <string>
using namespace std;
class Function {
public:
list<string> func{ "输出文本"};
vector<void(*)()> m_vecFuc = {Cout}; //= { Cout }; //这个地方要求不需要调用就可以储存进去
void Cout(int n){
cout << n;
}
string GetFunctionIndex(int index) {
auto it = func.begin();
advance(it,index);
return *it;
}
list<string> GetFunction() {
return func;
}
void RunFunctionIndex(int index,//这里还需要可以传递不同函数的参数) {
//这里要求可以根据index查询到对应的函数并且运行
}
};