Build creator Model

Source: Internet
Author: User

#include <iostream>usingnamespace Std;//Do not know why it is actually very good to explain the things on the internet to engage the people who are disoriented, the following is my understanding. //A base class derives a number of specific implementations of subclasses that implement the public methods of the virtual base class .then we construct a Direver object, let the base class be his member variable, at the time of the call//can choose any subclass object to pass in and then can call the method of the subclass, is it very simple? //"The intent of the generator mode is to separate a complex construct from its presentation" I'm really tangled up in the truth.//A half-day, do not want to handle the specific invocation of the class with a class wrapped up said so high-profile, I was drunk. //A little more popular, I fry a dish, with eggs can also fry, with meat can also fry, with Cucumber can also fry, Rice//table is equivalent to a packing class, you can take what dish I eat, no matter how many dishes you have. Class base{ Public:Virtual void Printfname() =0;Virtual voidPrintfschool () =0;}; Class Student1: Publicbase{ Public:void Printfname() {cout <<"Student1name"<< Endl; }voidPrintfschool () {cout <<"Student1school"<<endl; }};class Student2: Publicbase{ Public:void Printfname() {cout <<"Student2name"<< Endl; }voidPrintfschool () {cout <<"Student2school"<< Endl; }};class direver{ Public:Direver(Base *Base) {pbase =Base; }voidConstruct () {pbase->printfname ();    Pbase->printfschool (); }Private: Base *pbase;};intMain () {Direver D (NewStudent2 ());//Specify the child class object to be passed in here. D.construct ();//Haha, here are the objects and methods in the subclass you want to invoke.     return 0;}

Build creator Model

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.