I'm setting up a finite state machine structure as a proof of concept to be used in other projects. The states have function pointers that point to actions they are allowed to perform during certain events and transitions. I'm trying to restrict these pointers to be a part of a certain namespace, but the compiler doesn't recognize the namespace. The exact error is " StateAction': is not a class or namespace name. I've whittled out code until just these lines below remain.
//In State.h file
#pragma once
#include "StateAction.h"
class CState {
public:
void addAction(void (StateAction::*funcPtr)()) { m_func = funcPtr; } //error line
private:
void (StateAction::*m_func)(); //error line
};
//In StateAction.h file
#pragma once
#include <iostream>
namespace StateAction {
void fun1();
void fun2();
};
//In StateAction.cpp file
#include "StateAction.h"
void StateAction::fun1() {
std::cout << "func 1" << std::endl;
}
void StateAction::fun2() {
std::cout << "func 2" << std::endl;
}
Any suggestions are appreciated. Most searches on this error are about circular dependencies, so I haven't been able to find much info. Is it even possible to restrict a function pointer to a namespace? I'm almost positive I've done this before with classes.