mercredi 29 avril 2015

How to define template member functions of nested struct outside header? [duplicate]

This question already has an answer here:

I'm using the boost meta state machine and have it working, until I change the member functions to declarations and move the function definitions out of the *.h and into the *.cpp files. After doing so, I end up with undefined references.

namespace test
{
    // ...

    struct player_ : public msm::front::state_machine_def<player_>
    {
        template <class Event,class FSM>
        void on_entry(Event const& ,FSM&);

        struct Empty : public msm::front::state<> 
        {    
            template <class Event,class FSM>
            void on_entry(Event const& ,FSM&);
        };

        // ...
    };
}

The problem I end up w/ is undefined references when linking. Here is how I've tried to define the template member functions.

template <class Event, class FSM>
void player_::on_entry(Event const&, FSM&)
{
    cout << "entering: Player" << endl;
}

template <class Event, class FSM>
void player_::Empty::on_entry(Event const&, FSM&)
{
    cout << "entering: Stopped" << endl;
}

Aucun commentaire:

Enregistrer un commentaire