Jarrod
Jarrod

Reputation: 11

error C2064: term does not evaluate to a function taking 0 arguments

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?

Upvotes: 1

Views: 5890

Answers (3)

Bart van Ingen Schenau
Bart van Ingen Schenau

Reputation: 15768

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])();

Upvotes: 2

Diego Sevilla
Diego Sevilla

Reputation: 29021

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...

Upvotes: 4

Šimon Tóth
Šimon Tóth

Reputation: 36441

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

Upvotes: 0

Related Questions