Intermediary mode (C ++)

Source: Internet
Author: User
# Include <iostream >#include <string> using namespace STD; Class absperson; Class absmed {public: absmed () {} virtual ~ Absmed () {} virtual void send (string, absperson *) = 0; virtual void set (absperson *, absperson *) = 0 ;}; class absperson {public: absperson () {} virtual ~ Absperson () {} virtual void send (string) = 0; virtual void get (string) = 0; protected: absmed * p_med;}; Class person_buy: Public absperson {public: person_buy (absmed * P) {p_med = P;} virtual ~ Person_buy () {} void send (string Str) {p_med-> send (STR, this);} void get (string Str) {cout <"buyer information: "<STR <Endl ;}}; class person_detail: Public absperson {public: person_detail (absmed * P) {p_med = P;} virtual ~ Person_detail () {} void send (string Str) {p_med-> send (STR, this);} void get (string Str) {cout <"seller information: "<STR <Endl ;}}; class med: Public absmed {protected: absperson * person1; absperson * person2; public: MED () {} virtual ~ Med () {} void send (string STR, absperson * P) {If (P = person1) person2-> get (STR ); else person1-> get (STR);} void set (absperson * P1, absperson * P2) {person1 = p1; person2 = P2 ;}; int main () {absmed * p_med = new med; absperson * p_buy = new person_buy (p_med); absperson * p_limit = new person_med (p_med); p_med-> set (p_buy, p_limit ); p_buy-> send ("I want to buy a computer"); p_prop-> send ("brother sold not a computer, is lonely"); p_buy-> send ("okay, you won "); Delete p_med; Delete p_buy; Delete p_buckets; System (" pause "); Return 0 ;}

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.