views:

56

answers:

3

In some code I'm writing, I have the following line, which gives me error C2064:

rs_opCodes[cur_block]();

rs_opCodes is defined as such:

typedef void (rsInterpreter::*rs_opCode)();
rs_opCode rs_opCodes[NUM_OPCODES];

Does anyone know why I'm recieved error C2064?

A: 

You defined rs_opCode to be a method pointer but you are using it as function pointer.

Let_Me_Be
+3  A: 

You have to use the syntax of method pointer call, but you need an object to which make the actual call. Note that the typedef stablishes that you're defining pointers to a method of objects of type rsInterpreter, so you need an object of that type:

rsInterpreter r;
(r.*rs_opCodes[cur_block])();

However, the whole idea of this doesn't make much sense to me. You're writting an array of method pointers to be called in objects... I can't, at first thought, come up out of my mind of an usable example of this type of code...

Diego Sevilla
I figured that I wouldn't have to since the line was in a member function. I suppose I was wrong. Thanks!
Jarrod
"I can't, at first thought..." - I would say that `rsInterpreter` is a virtual machine, and `rs_opCodes` is a program. Instead of the opcodes being encoded as integers, they are encoded as member function pointers. An operation is executed by calling the corresponding member function on the VM. It's a limited VM model, because there's no place for immediate values in the opcodes, but it can fly.
Steve Jessop
@Steve: Thanks! I just didn't think of actually interpreting the variable names :)
Diego Sevilla
A: 

You defined rs_opCode as a pointer to a member function (of class rsInterpreter). To call such a beast, you need the sytax

(object.*rs_opCodes[cur_block])();

or

(pointer->*rs_opCodes[curr_block])();
Bart van Ingen Schenau