#include "stdafx.h" #include <iostream> #define _NRT_SECURITY_NO_WANING using namespace std; class IProgram { public: virtual void getSal()=0; }; class Program:IProgram { public: Program(char *name,int sal) { this->sal = sal; this->name = name; } protected: char* name; int sal; public: // 通过 IProgram 继承 virtual void getSal() override { cout << "name: " << name << " sal: " << sal << endl; } }; class supperPrograma : public Program,public IProgram { public : supperPrograma(char *name,int sal):Program(name,sal) { } // 通过 IProgram 继承 virtual void getSal() override { Program(this->name, this->sal).getSal(); } }; class midPrograma : public Program , public IProgram { public: midPrograma(char *name, int sal) :Program(name, sal) { } // 通过 IProgram 继承 virtual void getSal() override { Program(this->name, this->sal).getSal(); } }; class changjing { public: void dis(IProgram* p) { p->getSal(); } }; void main() { changjing* c = new changjing(); c->dis(new supperPrograma ("张三",1000)); system("pause"); }