boost.utility的base_from_member

来源:互联网 发布:控制微信摇骰子软件 编辑:程序博客网 时间:2024/06/06 22:59
// base_from_member.cpp // made by davidsu33// 2014-9-28#include "stdafx.h"#include <boost/utility/base_from_member.hpp>#include <boost/core/addressof.hpp>#include <string>typedef int RGBA;using namespace std;//手class BaseHand{public:BaseHand(RGBA color):m_rgba(color){}virtual ~BaseHand(){}private:RGBA m_rgba;};//脚class BaseFoot{public:BaseFoot(int size, const std::string& style):m_size(size),m_style(style){};virtual ~BaseFoot(){}private:int m_size;std::string m_style;};//头class BaseHead{public:BaseHead(int width, int height):  m_width(width),m_height(height){};  virtual ~BaseHead(){}private:int m_width;int m_height;};//NPCclass GameNPC : public BaseHand,public BaseFoot,public BaseHead{public:GameNPC(RGBA rgba, int footsize, const std::string& footstyle,int headWidth, int headHeight):BaseHand(rgba),BaseFoot(footsize, footstyle),BaseHead(headWidth, headHeight){}};//base_from_memberclass BFMGameNPC :public boost::base_from_member<BaseHand>,boost::base_from_member<BaseFoot>,boost::base_from_member<BaseHead>{public:typedef boost::base_from_member<BaseHand> pbase0_type;typedef boost::base_from_member<BaseFoot> pbase1_type;typedef boost::base_from_member<BaseHead> pbase2_type;public:BFMGameNPC();~BFMGameNPC();};BFMGameNPC::BFMGameNPC()//简化多参数的继承:pbase0_type(1002),pbase1_type(2, "pegine"),pbase2_type(100, 200){}BFMGameNPC::~BFMGameNPC(){}int _tmain(int argc, _TCHAR* argv[]){BFMGameNPC bfmnp;GameNPC npc(10002, 2, "pengine", 100, 200);return 0;}

0 0