首页 > 代码库 > boost库shared_ptr实现桥接模式
boost库shared_ptr实现桥接模式
主程序
/*将抽象部分与实现部分分离,使它们都可以独立的变化*/ #include "bridge.h" int main() { cout <<"main start" <<endl; sample smp; smp.display(); cout <<"main end" <<endl; //sample::bridge bri; //error: ‘class sample::bridge’ is private return 0; }
bridge.h
#include <boost/smart_ptr.hpp> #include <iostream> using namespace boost; using namespace std; class sample { private: class bridge; shared_ptr<bridge> bptr; public: sample(); void display(); }; class sample::bridge { public: void display(); };
bridge.cpp
#include "bridge.h" sample::sample() { bptr = make_shared<bridge>(); } void sample::display() { bptr->display(); } void sample::bridge::display() { cout << "bridge display!"<<endl; }
makefile
.SUFFIXES:.h .c .cpp .o CC=$(CXX) $(CXX_FLAG) RM = rm SRCS = bridge.cpp main.cpp PROGRAM = bridge OBJS=$(SRCS:.cpp=.o) INC_PATH = -I$(BOOST_INCLUDE) LIB_PATH = -L$(BOOST_LIB) LIBS = -lboost_date_time $(PROGRAM):$(OBJS) $(CC) $? $(LIB_PATH) $(LIBS) -o $@ $(OBJS):$(SRCS) $(CC) $(CPPFLAGS) -c $(SRCS) $(INC_PATH) .PHONY:clean clean: $(RM) $(PROGRAM) $(OBJS)
boost库shared_ptr实现桥接模式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。