#include<iostream> using namespace std; class DBOperator{ public: virtual void connDB()=0; void openDB(){ cout<<"打开数据库"<<endl; } void useDB(){ cout<<"使用数据库"<<endl; } void closeDB(){ cout<<"关闭数据库"<<endl; } void process(){ connDB(); openDB(); useDB(); closeDB(); } }; class SQLServerDB:public DBOperator{ public: void connDB(){ cout<<"连接SQL Server数据库"<<endl; } }; class OracleDB:public DBOperator{ public: void connDB(){ cout<<"连接Oracle数据库"<<endl; } }; int main(){ int i; DBOperator *db=NULL; cout<<"请选择:1、SQL Server\t 2、Oracle"<<endl; cin>>i; if(i==1){ db=new SQLServerDB(); }else if(i==2){ db=new OracleDB(); }else{ cout<<"输入有误!"<<endl; } db->process(); delete db; }
标签:模版,void,db,模式,else,new,方法 From: https://www.cnblogs.com/qiuyutingyyds/p/17001601.html