【发布时间】:2018-07-11 15:12:30
【问题描述】:
无法确定 TSm_ 中违反了哪条规则。 Sm_ 已编译,TSm_ 未编译:
错误 C2974:'boost::mpl::vector':'T0' 的模板参数无效, 预期类型
错误 C2974:“boost::mpl::vector”:“T3”的模板参数无效, 预期类型
区别在于 TSm_ 是模板,而 Sm_ 不是。
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
namespace msm = boost::msm;
namespace mpl = boost::mpl;
struct Event {};
class Sm_ : public msm::front::state_machine_def<Sm_>
{
public:
using Me = Sm_;
struct First : public msm::front::state<>
{};
using initial_state = First;
struct Second : public msm::front::state<>
{};
void trans(const Event& /*e*/)
{}
struct transition_table : public mpl::vector<
a_row<First, Event, Second, &Me::trans>
>
{};
};
using Sm = msm::back::state_machine<Sm_>;
// broken one
enum class Side : char
{
Buy = 0, Sell = 1
};
template <Side side>
class TSm_ : public msm::front::state_machine_def<TSm_<side>>
{
public:
using Me = TSm_<side>;
using Base = msm::front::state_machine_def<Me>;
using Base::a_row;
struct First : public msm::front::state<>
{};
using initial_state = First;
struct Second : public msm::front::state<>
{};
void trans(const Event& /*e*/)
{}
struct transition_table : public mpl::vector<
a_row<First, Event, Second, &Me::trans> // compilation is failed here
>
{};
};
template <Side side>
using TSm = msm::back::state_machine<TSm_<side>>;
请帮忙
更新
我找到了编译的方法:a_row 不是类型而是模板,它的别名也应该是模板
struct Begin {};
template <Side side>
class TSm_ : public msm::front::state_machine_def<TSm_<side>>
{
public:
//-----------------------------------------------------------------------------------------------------
using Me = TSm_<side>;
using Base = msm::front::state_machine_def<Me>;
template<
typename T1
, class Event
, typename T2
, void (Me::*action)(Event const&)
>
using a_row = typename Base::a_row;
//-----------------------------------------------------------------------------------------------------
struct First : public msm::front::state<>
{};
//-----------------------------------------------------------------------------------------------------
using initial_state = First;
//-----------------------------------------------------------------------------------------------------
struct Second : public msm::front::state<>
{};
//-----------------------------------------------------------------------------------------------------
void trans(const Begin& /*e*/)
{}
//-----------------------------------------------------------------------------------------------------
struct transition_table : public mpl::vector<
a_row<First, Begin, Second, &Me::trans>
>
{};
};
【问题讨论】: