📄 decorator.cpp
字号:
#include <string>
#include <iostream>
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) {}
virtual string getHTML() const {
return "<B>" + mWrapped.getHTML() + "</B>";
}
protected:
const Paragraph& mWrapped;
};
class ItalicParagraph : public Paragraph
{
public:
ItalicParagraph(const Paragraph& inParagraph) :
Paragraph(""), mWrapped(inParagraph) {}
virtual string getHTML() const {
return "<I>" + mWrapped.getHTML() + "</I>";
}
protected:
const Paragraph& mWrapped;
};
int main(int argc, char** argv)
{
Paragraph p("A party? For me? Thanks!");
// Bold
cout << BoldParagraph(p).getHTML() << endl;
// Bold and Italic
cout << ItalicParagraph(BoldParagraph(p)).getHTML() << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -