【发布时间】:2018-12-22 15:38:18
【问题描述】:
我尝试创建可以接收函数指针的队列 - 但我不知道该怎么做
这是我的代码
struct TaskElement
{
int id;
std::function<void()> func;
void operator()()
{
func();
}
};
int main()
{
MyMath* myMathElement = new MyMath();
myMathElement->Print_1();
Queue<TaskElement> myQueue;
TaskElement t1;
t1.id = 1;
t1.func = myMathElement->Print_1;
TaskElement t2;
t2.id = 2;
t2.func = &myMathElement->Print_2;
myQueue.push(t1); Error !!! &': illegal operation on bound member function expression
myQueue.push(t2); Error !!! &': illegal operation on bound member function expression
auto rec1 = myQueue.pop();
rec1();
std::cin.get();
}
【问题讨论】:
-
这令人困惑。您似乎已经在 stackoverflow.com 上呆了足够长的时间,知道“我的代码不起作用”形式的所有问题都必须满足 minimal reproducible example 的所有要求,如 stackoverflow.com 的 help center 中所述。这个在多个方面都无法满足minimal reproducible example 的要求,没有人应该向您指出这一点。
-
我学了C++……还是不知道好不好的问题……抱歉
标签: c++ c++11 visual-c++