Bubbles的声明如下:
vector< CBubble* > Bubbles;
有一般代码如下:
if( row == (Rows - 1) )
{//结束游戏
delete Current;
State = GAME_ENDED;
vector< CBubble* >::iterator itr = Bubbles.begin();
for( ; itr != Bubbles.end(); ++itr)
{
point2d pt;
CBubble* pB = *itr;
pB->GetPos( pt );
pB->Launch();
                  delete *itr;//这句有问题。
}
Bubbles.clear();
Game->Reset();
return;
}
如果将delete *itr;这句删除,则程序执行正常,加上这句的话,进行过程中非法退出,没有任何提示,各位高手看看,是什么问题?

解决方案 »

  1.   

    你这儿就delete了,其它地方是不是还在引用呢?pB->Launch();???
      

  2.   

    delete *itr;//这句有问题。
    itr不是new出来的啊!为什么要用delete
      

  3.   

    vector< CBubble* > Bubbles;
    有一般代码如下:
    if( row == (Rows - 1) )
    {//结束游戏
    delete Current;
    State = GAME_ENDED;
    // vector< CBubble* >::iterator itr = Bubbles.begin();
    // for( ; itr != Bubbles.end(); ++itr)
    vector< CBubble* >::iterator itr = Bubbles.end();
    for( ; itr != Bubbles.begin(); --itr) {
    point2d pt;
    CBubble* pB = *itr;
    pB->GetPos( pt );
    pB->Launch();
                      delete *itr;//这句有问题。
    }
    Bubbles.clear();
    Game->Reset();
    return;
    }
      

  4.   

    容器中的对象肯定都是new出来的。delete之后,直接就返回了,不应该还有明的地方引用了这个指针。
      

  5.   

    而且这个指针,只存在于容器中,我在delete之后,己经将容器,clear掉了。
      

  6.   

    此容保存的是指针不用delete的,由分配它的delete。
      

  7.   

    不管怎么样你的程序里面new和delete要配对!
      

  8.   

    容器自己会delete,如果你调用了,它还delete,就出错啦
      

  9.   

    Your snippet's has no bugs. I have programmed a test as below,and it works fine.
    ----------------------------
    #include <stdio.h>
    #include <vector>
    using namespace std;class CBubble
    {
    public:
    CBubble(int a)
    {
    m_a=a;
    printf("Constructor for %d called\n",m_a);
    };
    ~CBubble()
    {
    printf("Desturctor for %d called\n",m_a);
    };
    void ShowValue()
    {
    printf("Value is:%d\n",m_a);
    }
    int m_a;
    double m_b;
    };void main()
    {
    vector< CBubble* > Bubbles;
    //Initialze.....
    Bubbles.push_back(new CBubble(1));
        Bubbles.push_back(new CBubble(2));
    Bubbles.push_back(new CBubble(3));
    //Destuctor
    vector< CBubble* >::iterator itr = Bubbles.begin();
    for( ; itr != Bubbles.end(); ++itr)
    {
    CBubble* pB = *itr;
    pB->ShowValue();
                      delete *itr;//这句有问题。
    }
        Bubbles.clear();}
    -------------------------------------------------
    There is no debug error,So I think the problem lies in the 
    "
    pB->GetPos( pt );
    pB->Launch();
    "
    Make sure that your have cleaned up all the staffs before deleting the objects.