gpt4 book ai didi

c++ - 成员函数 vector

转载 作者:行者123 更新时间:2023-11-30 03:25:39 24 4
gpt4 key购买 nike

<分区>

使用 vector 来安排类的方法调用的方法是什么。我想要一个方法 vector ,像这样:

class Model {
using task_t = std::function<void()>;
std::vector<std::vector<task_t>> _frameTasks;

void add_function() { _frameTasks[3].push_back(&(this->function()); }
void function() {std::cout << "hi"; }
void step() {
for (auto task : _frameTasks[3]) task();
}
}

但是编译器提示说:

error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. 

我该如何解决这个问题或什么是正确的方法?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com