Visitor模式实践

来源:互联网 发布:kali linux安装到手机 编辑:程序博客网 时间:2024/04/25 16:30
刚刚学习了一下设计模式的VISTOR模式,感觉里面的限制是比较大。要使用虚拟成员,固定的类层次结构。于是想实现以个更简单的visitor模 式。 使用了boost里面的function和绑定库,因为c++标准对type_info支持的太少,高性能而又可移植实现现在还想不到。所以就使用了VC对 type_info的扩充功能raw_name。 实现与源码如下: #include #include #include #include #include #include class multi_function { public: typedef multi_function self_type; private: struct op_type { op_type(void (self_type::*cast) (boost::any &) const, boost::function1 const &op) :m_cast(cast), m_fun(op) { } void (self_type::*m_cast)(boost::any &) const; boost::function1 m_fun; op_type() :m_cast(0), m_fun(){} }; typedef std::map
原创粉丝点击