I've checked multiple answers that are asking similar things but nothing has been working with me so far.
here's my class
class VirtualMachine
{
private:
typedef void(VirtualMachine::*FunctionOfOperator)(Operands);
//a map is used to link operator functions with the enum
//representing the operator in the instruction
//to call the function representing the ADD operator:
//instructionFunctions[ADD](Operands);
//this will execute the ADD instructions with the operands
//passed to the function
std::map<Operator, FunctionOfOperator> instructionFunctions;
//operator functions
void _ADD(Operands operands), _SUB(Operands operands), _MUL(Operands operands), _DIV(Operands operands),
_IDIV(Operands operands), _IREM(Operands operands), _ABS(Operands operands), _RND(Operands operands);
void mapInstructions();
...
}
void VirtualMachine::mapInstructions()
{
instructionFunctions[Operator::ADD] = &VirtualMachine::_ADD;
instructionFunctions[Operator::SUB] = &VirtualMachine::_SUB;
instructionFunctions[Operator::MUL] = &VirtualMachine::_MUL;
instructionFunctions[Operator::DIV] = &VirtualMachine::_DIV;
instructionFunctions[Operator::IDIV] = &VirtualMachine::_IDIV;
instructionFunctions[Operator::IREM] = &VirtualMachine::_IREM;
instructionFunctions[Operator::ABS] = &VirtualMachine::_ABS;
instructionFunctions[Operator::RND] = &VirtualMachine::_RND;
}
To call the function as shown in this answer:
(this->*instructionFunctions[translated_memory.at(pc).op])(translated_memory.at(pc).operands);
this is called inside VirtualMachine::runVM()
which is a public function
I've also tried using std::function
with bind
as shown here
I am getting error LNK2019: unresolved external symbol
Can someone please explain more about pointer to private memeber function not just how to solve this. before the Virtual Machine was not a class and the map to a pointer function was working fine and I was able to call functions.
thank you.