#include <iostream>
using namespace std;

class Road
{
public:
    Road(){}
    virtual ~Road(){}
    void operation()
    {
        start();
        step1();
        step2();
        step3();
        end();
    }
    void start(){cout<<"start"<<endl;}
    void end(){cout<<"end"<<endl;}
    virtual void step1()=0;
    virtual void step2()=0;
    virtual void step3()=0;
};

class way1 : public Road
{
public:
    way1(){}
    virtual ~way1(){}
    void step1(){cout<<"way1_step1"<<endl;}
    void step2(){cout<<"way1_step2"<<endl;}
    void step3(){cout<<"way1_step3"<<endl;}
};

class way2 : public Road
{
public:
    way2(){}
    virtual ~way2(){}
    void step1(){cout<<"way2_step1"<<endl;}
    void step2(){cout<<"way2_step2"<<endl;}
    void step3(){cout<<"way2_step3"<<endl;}
};

int main()
{
    Road *pr1=new way1;
    Road *pr2=new way2;

    pr1->operation();
    pr2->operation();

    delete pr2;
    delete pr1;

    system("pause");
    return 0;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2021-09-27
  • 2021-05-31
  • 2022-01-21
  • 2022-01-16
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
  • 2021-08-29
  • 2022-12-23
  • 2021-06-15
  • 2021-11-03
相关资源
相似解决方案