C + + Design mode-proxy mode

Source: Internet
Author: User

According to Cheng Jie's big talk mode:

1 //Proxy.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <string>7 using namespacestd;8 9 classGirlTen { One  Public: AGirl (stringName =""): Mname (name) {} -     stringGetName () -     { the         returnMname; -     } - Private: -     stringMname; + }; -  + classGivegift A { at  Public: -     Virtual voidGivedolls () =0; -     Virtual voidGiveflowers () =0; -     Virtual voidGivechocolate () =0; - }; -  in classPuisuit: PublicGivegift - { to  Public: + puisuit (Girl mm): Mgirl (mm) {} -     Virtual voidgivedolls () the     { *cout<<"Send"<<mgirl.getname () <<"Toys"<<Endl; $     }Panax Notoginseng     Virtual voidgiveflowers () -     { thecout<<"Send"<<mgirl.getname () <<"Flowers"<<Endl; +     } A     Virtual voidgivechocolate () the     { +cout<<"Send"<<mgirl.getname () <<"Chocolate"<<Endl; -     } $ Private: $ Girl Mgirl; - }; -  the classProxy: PublicGivegift - {Wuyi  Public: the Proxy (Girl mm) -     { WuMpuisuit =Newpuisuit (mm); -     } About     Virtual voidgivedolls () $     { -Mpuisuit->givedolls (); -     } -     Virtual voidgiveflowers () A     { +Mpuisuit->giveflowers (); the     } -     Virtual voidgivechocolate () $     { theMpuisuit->givechocolate (); the     } the Private: thepuisuit*Mpuisuit; - }; in int_tmain (intARGC, _tchar*argv[]) the { thecout<<"Proxy Mode"<<Endl; AboutGirl Girl ("Jiao Jiao"); the Proxy Pro (girl); the Pro. Givedolls (); the Pro. Giveflowers (); + Pro. Givechocolate (); -System"Pause"); the     return 0;Bayi}

C + + Design mode-proxy mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.