I posted a similar question earlier, just that now the problem is elsewhere.
I'm trying to make a MARIE code simulator, or whatever you would call it, and I'm trying to avoid a long switch case to access some private functions in the class.
MARIEapp.h:
MARIEapp.h{
public:
typedef void (MARIEapp::*Instruction)();
private:
static std::map<char, Instruction> MARIEinstruction;
void JnS();
void Load();
void Store();
void Add();
void Subt();
void Input();
void Output();
void Halt();
void Skipcond();
void Jump();
void Clear();
void AddI();
void JumpI();
void LoadI();
void StoreI();
void Execute();
};
MARIEapp.cpp:
static std::map<char, MARIEapp::Instruction> MARIEinstruction = {
{ '0', &MARIEapp::JnS },
{ '1', &MARIEapp::Load },
{ '2', &MARIEapp::Store },
{ '3', &MARIEapp::Add },
{ '4', &MARIEapp::Subt },
{ '5', &MARIEapp::Input },
{ '6', &MARIEapp::Output },
{ '7', &MARIEapp::Halt },
{ '8', &MARIEapp::Skipcond },
{ '9', &MARIEapp::Jump },
{ 'A', &MARIEapp::Clear },
{ 'B', &MARIEapp::AddI },
{ 'C', &MARIEapp::JumpI },
{ 'D', &MARIEapp::LoadI },
{ 'E', &MARIEapp::StoreI }
};
void MARIEapp::Execute() {
MARIEinstruction[IR[0]]();
if (DebugMode)ShowRegisters();
}
The long list of void functions access private members and are properly defined in the cpp file, as is the ShowRegister() function
The problem now is that in Execute() I get an error when accessing MARIEinstruction, saying "expression preceding parenthesis of apparent call must have (pointer-to-) function types".
Also are there any other ways you recommend I do this?
EDIT: IR is a string