创建和回推函数向量
Creating and pushing back a vector of functions
我想创建一个函数向量并"push_back"它,但不知道如何正确完成。谢谢,提前。这就是我到目前为止所拥有的:
int a = 1;
int b = 2;
int function1()
{
return (a+b)*c;
}
typedef std::function<int> function1;
typedef std::vector<function> functionsvector;
functionvector.push_back(function1);
你不应该在这里使用typedef
。这意味着您将这些类型别名为您指定的名称,而不是创建它们的实例。
您应该改为这样做:
//create a vector of functions which take no arguments and return an int
std::vector<std::function<int()>> functionvector {};
//implicitly converts the function pointer to a std::function<int()> and pushes
functionvector.push_back(function1);
相关文章:
- 函数向量_指针有不同的原型,我可以构建一个吗
- 如何使用向量的template_back函数
- 如何通过派生类函数更改基类中的向量
- 变量没有改变?通过向量的函数调用
- 一对向量构造函数:初始值设定项列表与显式构造
- 在c++中使用向量时,如何调用构造函数和析构函数
- std::sort()函数无法对向量的一部分进行排序
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- C++中函数的向量返回类型引发错误
- 添加存储在向量中的大整数的函数出现问题
- 如何在 c++ 中定义接受不同参数类型的函数向量?
- 具有 lambda 函数的函数向量
- 你能用参数制作函数向量吗?
- 在C++中使用成员函数向量时,有没有办法实现协变返回类型
- 在编写 lambda 函数向量时出现隔离错误
- 如何在 boost.process 间共享内存中使用复杂结构"push_back"函数向量
- 是否将std矢量重新分配到默认的构造函数向量是擦除的好方法
- 运行提升for_each中的成员函数向量
- 创建和回推函数向量
- C++,指向函数向量的指针的STL映射