【发布时间】:2011-09-24 20:10:39
【问题描述】:
我正在尝试存储函数的向量(或堆栈)。这个想法是我有一系列功能可以在主窗口中添加和删除小部件。我使用计时器警报,每当警报被调用时,我都会调用函数堆栈顶部的函数。
所以我的函数将始终是 void 类型。我的问题/误解是如何删除 stl::stack 的 void 函数以及如何执行该函数?
class InstructionScreen
{
std::stack <void*> instructionSteps; // is this how I declare a stack of functions
void runTimerEvent()
{
if ( !instructionSteps.empty() )
{
// call the function at the top of the stack
// how do I call the function?
(*instructionSteps.top()); // is that how?
instructionSteps.pop();
}
}
void step1()
{
// here I create some widgets & add them to the main window
}
void step2()
{
// delete widgets from window
// create some different widgets & add them to the main window
}
void buildStack()
{
instructionSteps.push( (&step1()) ); // is this correct?
instructionSteps.push( (&step2()) );
}
};
【问题讨论】: