box *p=new box1 ; 错了吗?请教……
#include<iostream>using namespace std;
class box
{
public:
box(int x,int y,int z)
{
chang=x;
kuan=y;
gao=z;
}
virtual void show ()
{
cout<<chang<<" "<<kuan<<" "<<gao<<endl;
}
virtual ~box()
{
cout<<"基类清理"<<endl;
}
protected:
int chang;
int kuan;
int gao;
};
class box1:public box
{
public:
box1(int x,int y,int z,int u):box(x,y,z)
{
color=u;
}
virtual void show()
{
cout<<chang<<" "<<kuan<<" "<<gao<<" "<<color<<endl;
}
virtual ~box1()
{
cout<<"派生类清理"<<endl;
}
protected:
int color;
};
int main()
{
box *p=new box1; //提示这里错了
delete p;
system("pause");
return(0);
}