刷题刷出新高度,偷偷领先!偷偷领先!偷偷领先! 关注我们,悄悄成为最优秀的自己!
(1) virtual void printInvoice()
(2) ticket->printInvoice()
(3) Decorator::printInvoice()
(4) Decorator::printInvoice()
(5) &a
本题主要考察了对C++中Decorator模式的理解以及类的继承、对象指针的运用。
(1)在Invoice类中,需要定义一个虚函数printInvoice(),用于打印发票的内容。
(2)在Decorator类的printInvoice()函数中,首先需要判断ticket指针是否为空,若不为空,则调用ticket指向的对象的printInvoice()函数,即ticket->printInvoice()。
(3)在HeadDecorator类的printInvoice()函数中,先打印发票的抬头,然后再调用基类Decorator的printInvoice()函数,故填Decorator::printInvoice()。
(4)在FootDecorator类的printlnvoice()函数中,应首先调用基类Decorator的printInvoice()函数,再打印发票的脚注,故填Decorator::printInvoice()。
(5)在main函数中,创建FootDecorator对象a,并将NULL赋值给其ticket成员,然后创建HeadDecorator对象b,将a的地址传给b的构造函数,所以在调用b的printInvoice()函数时,实际上打印的是a的抬头和脚注,故填&a。
本文链接:请填写应填入(n)处的字句。
版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。让学习像火箭一样快速,微信扫码,获取考试解析、体验刷题服务,开启你的学习加速器!
