本帖最后由 Angel丶L 于 2016-3-28 02:59 编辑 #include <iostream>
using namespace std;
class my_waste
{
public:
virtual void get() = 0;
virtual void run() = 0;
};
class one:public my_waste
{
public:
virtual void get() { cout << "我获得了1" << endl; }
virtual void run() { cout << "我是1!!!" << endl; }
};
class two :public my_waste
{
public:
virtual void get() { cout << "我获得了2" << endl; }
virtual void run() { cout << "我是2!!!" << endl; }
};
//{ cout << "我获得了1" << endl; }
//{ cout << "我是1" < , endl; }
int main()
{
void (my_waste::*pl) ()= 0;
my_waste *p1;
int check1, check2;
bool bbq = false;
while (1)
{
l:cout << "0退出 1one的 2two的" << endl;
cin >> check1;
switch (check1)
{
case 1:p1 = new one;break;
case 2:p1 = new two;break;
case 0:bbq = true;break;
default:cout << "非法操作" << endl;goto l;break;//死循环
}
if (bbq)
break;
j:cout << "操作的函数 1或者2" << endl;
cin >> check2;
switch (check2)
{
case 1:pl = &my_waste::get;break;
case 2:pl = &my_waste::run;break;
default:cout << "非法操作" << endl;goto j;break;//死循环
}
(p1->*pl)();
delete p1;
}
return 0;
}
输入字符就会出现 输入数字不会 |