#include<iostream.h>
#include<string.h>
//请大家议论以下我下面的程序中的[]是不是画蛇添足拉!
class AA
{
private:
int a;
public:
AA (int n):a(n){}
virtual~AA(){ cout<<"AA"<<endl; }
};
////////////////////////////////////////
class BB :public AA
{
private:
char *p;
public:
BB (int n,char* s): AA(n)
{
p=new char[strlen(s)+1];
strcpy(p,s);
}
~BB()
{
delete [] p;//delete p省略了[ ]程序正常运行!
cout<<"BB"<<endl;
}
};
///////////////////////////////////////
void main()
{
AA *p=new BB(5,"abcd");
delete []p; //delete p省略了[ ]程序可以正常运行!
}
[此贴子已经被作者于2006-10-1 15:11:12编辑过]