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);
}