用指针定义类的对象
#include<iostream.h>class dog
{ //see declaration of 'dog'
int q;
static int m;
public:
dog(int i)
{
q=i;
m++;
}
int getdog()
{
return m;
}
~dog()
{
m--;
cout<<"delete"<<' '<<m<<' '<<"object"<<endl;
}
};
int dog::m=0;
int main()
{
const int max=3;
dog *p;
p=new dog [max]; //error C2512: 'dog' : no appropriate default constructor available
for(int i=0;i<max;i++)
{
cout<<"establish"<<' '<<p[i]->getdog()<<' '<<"object"<<endl; //error C2227: left of '->getdog' must point to class/struct/union
}
delete[]p;
return 0;
}
程序出现三个错误,不明白如何修改