[求助]无法运行
#include <iostream>#include <stdlib.h>
#include<ctime>
using namespace std;
class tradespace{
public:
virtual void sayhi(){cout<<"jack hi"<<endl;}
};
class tailor:public tradespace{
public:
void sayhi(){cout<<"tailor hi"<<endl;}
};
class tinker:public tradespace{
public:
void sayhi(){cout<<"tinker hi"<<endl;}
};
int main(){
srand(time(0));
tradespace* p[10];
unsigned k,j;
for(j=0;j<10;j++)
k=1+rand()%3;
switch(k)
{
case 1:p[j]=new tradespace;break;
case 2:p[j]=new tailor;break;
case 3:p[j]=new tinker;break;
}
for(j=0;j<10;j++){
p[j]->sayhi();
delete p[j];
}
system("pause");
return 0;
}
编译通过 无法运行~~