I'm quite unfamiliar with C++ and I'm having some issues with executing a static member function pointer I've tried several different variations on the code (included below) and looked at several different tutorials and questions but I'm not having much luck!
Here's a code snippet for the header and source files plus the error's I'm getting:Actions.h
class Actions{
private:
int actionId;
int stateId;
int eventId;
public:
typedef string (Actions::*functionPtr)(int previousState, int currentState, int eventId);
static functionPtr _ptrAction1;
int doAction(int previousState, int currentState, int eventId);
string function1(int previousState, int currentState, int eventId);
};
Actions.c:
#include "stdafx.h"
#include "Actions.h"
Actions::Actions(int actionId, int stateId, int eventId){
this->actionId = actionId;
this->stateId = stateId;
this->eventId = eventId;
_ptrAction1 = &Actions::function1;
}
int doAction(int actionId, int previousState, int currentState, int eventId){
int functionId = 0;
string message;
switch(actionId){
case 1:
message = (*_ptrAction1)(previousState, currentState, eventId);
break;
default:
break;
}
}
string Actions::function1(int previousState, int currentState, int eventId){
return "this is an example for now";
}
The error I'm receiving is in Actions.c on line
message = (*_ptrAction1)(previousState, currentState, eventId);
The error is as follows:
1>Actions.cpp(37): error C2065: '_ptrAction1' : undeclared identifier
I thought perhaps I was referencing it incorrectly so I changed the above line to be as follows:
message = (*Actions::_ptrAction1)(previousState, currentState, eventId);
But now I receive a different error:
Actions.cpp(37): error C2064: term does not evaluate to a function taking 3 arguments
For reference I have read C++ calling static function pointer but it is not the same issue that I am having. I really hope you can help and I thank you for your time, I greatly appreciate it!
function1, only define it.