我正在为一个学校项目开发一个 C++ 小型虚拟机,它应该像 dc 命令一样工作,由输入输出元件、芯片组、CPU 和 RAM 组成。我目前正在研究芯片组,其中我实现了一个小的解析类,以便能够从标准输入或文件中获取一些 Asm 指令,然后将这些指令推送到 CPU。
问题是:我的指令在 std::list 中排序,我希望能够使用 foreach 指令逐个推送它们。为此,我需要能够调用我的成员函数“push_instruction”作为 for_each 的函数指针 F;而且我找不到做到这一点的技巧......
有任何想法吗?
这是我的代码:
/*
** Function which will supervise
** the lexing and parsing of the input (whether it's std_input or a file descriptor)
** the memory pushing of operands and operators
** and will command the execution of instructions to the Cpu
*/
void Chipset::startExecution()
{
/*
** My parsing
** Instructions
**
*/
for_each(this->_instructList.begin(), this->_instructList.end(), this->pushInstruction);
}
void Chipset::pushInstruction(instructionList* instruction)
{
if (instruction->opCode == PUSH)
this->_processor->pushOperand(instruction->value, Memory::OPERAND, Memory::BACK);
else if (instruction->opCode == ASSERT)
this->_processor->pushOperand(instruction->value, Memory::ASSERT, Memory::BACK);
else
this->_processor->pushOperation(instruction->opCode);
}
std::for_each(
_instructList.begin(),
_instructList.end(),
std::bind1st(std::mem_fun(&Chipset::pushInstruction), this));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)