65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
class Paragraph
{
public:
Paragraph(const string& inInitialText) : mText(inInitialText) {
}
virtual string getHTML() const { return mText; }
protected:
string mText;
};
class BoldParagraph : public Paragraph
{
public:
BoldParagraph(const Paragraph& inParagraph) :
Paragraph(""), mWrapped(inParagraph) {
cout << "1 " << endl;
}
BoldParagraph(const BoldParagraph& rhs)
:Paragraph(rhs.mText)
,mWrapped(rhs.mWrapped)
{
cout << "2 " << endl;
}
void operator = (BoldParagraph& rhs)
{
cout << "3 " << endl;
}
virtual string getHTML() const {
return " <B>" + mWrapped.getHTML() + " </B>";
}
protected:
const Paragraph& mWrapped;
};
void main()
{
Paragraph p("A party? For me? Thanks!");
//cout << BoldParagraph(BoldParagraph(p)).getHTML().c_str()<< endl;
BoldParagraph bold(p);
//Bold
cout << BoldParagraph(bold).getHTML().c_str() << endl;
}