请教:
编译工具:VS2005 vc
我在一段程序中 开辟了空间,然后删除空间第一次运行这段程序没有问题第二次运行这段程序就出现:
Debug Assertion Failed!
File:dbgdel.cpp
Line:52Expresssion:_block_type_is_valid(pmead->nblockuse)For information on how your program can cause an assertion
failure,see the visual c++ documentation on asserts我的开辟:
int a[10]
a[0] new [size(int)]
a[1] new [size(int)]
我的删除:
delete a[0]
delete a[1]是不是我的删除写错了,
还是别的原因?
还有:
运行时库:
多线程(/MT)
多线程调试(/MTD)
多线程 DLL(/MD)
多线程 DLL(/MDd)这几种分别是什么意思?
一般要选哪种?谢谢!

解决方案 »

  1.   

    对指针理解有错误int* p = new int[4];
    delete p[];
      

  2.   

    int a[10]   // 已经是在栈里面分配空间了 
    a[0] new [size(int)] //new 是在堆里分配 由于a[0]已有空间了,故a可能不会指向new出来的那段地址
    a[1] new [size(int)] 
    至于delete a[0] delete a[1] 就更错误了 相当于 delete int,这样怎么行, 
    正确写法 delete a[],但是这样也不对 因为a可能指向的是栈里面分配地址空间,不能delete
    正确用法:
    int * pA = new int[10];
    ...
    if(pA)
      delete pA[];
    ps:个人意见,不过楼主要看看c/c++基础了,这是最基本的指针数组用法!
      

  3.   

    hgeAnimation* AniResultGameOver[12] = {NULL};for(char8 i = 0; i < 12; i ++)
    {
      AniResultGameOver[i]   = new  hgeAnimation(TexResultGameOver[i],8,6,0.0f,0.0f,
                          float (hge->Texture_GetWidth(TexResultGameOver[i],true)/2),
      float (hge->Texture_GetHeight(TexResultGameOver[i],true)/4)); 
      AniResultGameOver[i]->Play();
    }for(char8 i = 0; i < 12; i ++)
    {
    delete AniResultGameOver[i];                 //Result GameOver
    }
            
    其实,是这样的我删除的写法错在哪里啊?
    谢谢!
      

  4.   

    逻辑没问题, 看看hgeAnimation这个的原型吧,尤其是析构函数!