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 privatereturn 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 .oCC=$(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实现桥接模式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转] Java中的static关键字解
- 下一篇: 软件测试的基本知识