Originally Posted by
seizmic
but i doesn't solve the problem!!!
It shure does solve one of your problems. And there are more. Another one is that there is and has never been void main() in C++ and such crappy code doesn't compile on a decent compiler. It's int main(). ( this solves another problem ).
And now to what seems to be the problem.
You have to supply an instance if you want to call a non static classmenberfunction.
I have rearranged your program and don't know if what is left still does what you want.
Code:
#include <iostream>
using namespace std;
typedef unsigned int uint32_t;
struct Instruction;
class Test {
public:
Test();
virtual ~Test();
void i_adc(uint32_t opcode) {
cout << "i_adc(" << opcode << ")" << endl;
}
void r_adc(uint32_t opcode) {
cout << "r_adc(" << opcode << ")" << endl;
}
void execute();
private:
Instruction* instructionsA;
};
typedef void (Test::*InstructionProc)(uint32_t icode);
struct Instruction {
uint32_t mask;
uint32_t value;
char *name;
InstructionProc proc;
Instruction(uint32_t mask, uint32_t value, char* name, InstructionProc proc )
{
this->mask = mask;
this->value = value;
this->name = name;
this->proc = proc;
}
Instruction() {
}
void execute(Test & a, uint32_t param ) {
(a.*proc)(param);
}
};
inline Test::Test(){
instructionsA = new Instruction[2];
instructionsA[0] = Instruction(0x0de00000, 0x00a00000, "adc", &Test::i_adc);
instructionsA[1] = Instruction(0x0de00000, 0x00a00000, "adc", &Test::r_adc);
}
inline Test::~Test() {
delete [] instructionsA;
}
inline void Test::execute() {
instructionsA[0].execute(*this, 123);
instructionsA[1].execute(*this, 321);
}
int main() {
Test *cpu;
cpu = new Test();
cpu->execute();
return 0;
}
Kurt