其他语言

本类阅读TOP10

·基于Solaris 开发环境的整体构思
·使用AutoMake轻松生成Makefile
·BCB数据库图像保存技术
·GNU中的Makefile
·射频芯片nRF401天线设计的分析
·iframe 的自适应高度
·BCB之Socket通信
·软件企业如何实施CMM
·入门系列--OpenGL最简单的入门
·WIN95中日志钩子(JournalRecord Hook)的使用

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
C++ Design Pattern:Adapter

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

From this day onwards,I will start to learn C++ Design pattern.& I will write down my comprehensions and feelings.(for the purpose of self-examination,and communicating with newbies as me.)
 
(Adapterd from lxgljj's article in JAVA.)
#include <iostream>
#include <string>
using namespace std;

class PostedBook
{
public:
 PostedBook( const string& rhs)
 {
  this->m_StringNO_ = rhs;
 }
 PostedBook( const PostedBook& rhs )
 {
  this->m_StringNO_ = rhs.m_StringNO_;
 }
 const PostedBook& operator=( const PostedBook& rhs )
 {
  this->m_StringNO_ = rhs.m_StringNO_;
  return *this;
 }
 string GetPhoneNoFromBook()
 {
  return ( m_StringNO_ );
 }
private:
 string m_StringNO_;
};

class TellFriend
{
public:
 void TellSth()
 {
  cout<<"Azure's phone number: ";
 }
};

class TellFriendPhoneNo:public TellFriend
{
public:
 TellFriendPhoneNo( const PostedBook& pb ):m_PostedBook_(pb)
 {
  //Nothing needed to be done.
 }
 void TellPhoneNumber()
 {
  cout<<m_PostedBook_.GetPhoneNoFromBook()<<endl;
 }
private:
 PostedBook m_PostedBook_;
};


int main()

 PostedBook pb("13973284801");
 TellFriendPhoneNo gp(pb);
 gp.TellSth();
 gp.TellPhoneNumber();

 return (1);
}




相关文章

相关软件