码迷,mamicode.com
首页 > 其他好文 > 详细

boost库shared_ptr实现桥接模式

时间:2014-10-11 12:44:55      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:blog   io   os   ar   sp   2014   art   on   log   

主程序

/*将抽象部分与实现部分分离,使它们都可以独立的变化*/
#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实现桥接模式

标签:blog   io   os   ar   sp   2014   art   on   log   

原文地址:http://blog.csdn.net/leeboy_wang/article/details/39990479

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!