请问这段代码为什么编译正常,运行时却出错!
include <iostream>#include <vector>
using namespace std;
class counted{
int id;
static int count ;
public:
counted():id(count++){
cout<<id<<endl<<"it's being created"<<endl;
}
~counted(){
cout<<id--<<endl<<"it's being destroyed"<<endl;
}
};
int counted::count = 0;
int main(){
vector<counted*> countArray;
for(int i=0;i<5;i++)
{
if((countArray[i] = new counted)==0)
cerr<<"内存申请失败";
}
return 1;
}