<分区>
我想创建一个方法 schedule_function
将指向 BasicAlgo
对象的成员函数的指针保存到 ScheduledEvent
中,但没有BasicAlgo
的父类 Strategy
中定义的函数。现在我正在使用这种方法,它可以很好地保存 Strategy
中的函数,但不适用于 BasicAlgo
函数:
class Strategy {
schedule_function(void (Strategy::*func)()) {
// Puts the scheduled event built with the strategy function onto a list
heap_eventlist.emplace_back(std::make_unique<events::ScheduledEvent>(func));
}}
我尝试用 Strategy*::*func
替换 Strategy::*func
但这导致了编译器错误,而且看起来不正确。
有什么方法可以让派生类 BaseAlgo
的成员函数指针作为参数 in 基类 Strategy
,没有在 Strategy
中定义函数?