#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