标题:请问这段代码为什么编译正常,运行时却出错!
取消只看楼主
haitao9999
Rank: 2
等 级:论坛游民
帖 子:30
专家分:39
注 册:2006-4-10
结帖率:33.33%
已结贴  问题点数:15 回复次数:0 
请问这段代码为什么编译正常,运行时却出错!
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;
}
搜索更多相关主题的帖子: 编译 运行 代码 
2009-10-21 21:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-289423-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.596890 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved