r-lyeh-archived/fsm

duplicate symbol

Closed this issue · 2 comments


case 1


A.h
class A
{
fsm::stack fsm
}


A.cpp
fsm::state fighting("fighting");


B.h include A.h
C.h include A.h
In this case I can't do: fsm.start(fighting)


case 2


A.h
fsm::state fighting("fighting");
class A
{
fsm::stack fsm
}


A.cpp


B.h include A.h
C.h include A.h
In this case "duplicate symbol" error ,

How B & C can call A.fsm.start(fighting)

fsm((fsm::state)"walk");
fsm.start((fsm::state)"walking");

This is work~~~

That may work but there are better ways to do it, like following one:

//A.h
#include "fsm.hpp"
extern fsm::state fighting;
class A {
    public:
    fsm::stack fsm;
};
//A.cpp
#include "A.h"
fsm::state fighting("fighting");

And then in code (A.B or C cpp files...)

#include "A.h"

int main() {
A a;
a.fsm.start( fighting );
}