typedef struct _TUWENDES
{
   String strPic;
   String strContent;
}TuWenDes,*pTuWenDes;
vector<TuWenDes *> TuWenBlock;void __fastcall TForm10::Button1Click(TObject *Sender)
{
  pTuWenDes pTuWenDesTemp =new TuWenDes();
  if (pTuWenDesTemp==NULL)
  return;
  pTuWenDesTemp->strPic = strPicPath;
  pTuWenDesTemp->strContent= RichEdit1->Text;
  if (pTuWenDesTemp->strContent.Length()==0)
  return;  bool find =false;
  int i=0;
  for(;i<TuWenBlock.size(); i++)
  {
    if (TuWenBlock[i]->strPic==strPicPath)
    {
        find = true;
        break;
    }
  }
  if (find)
  {
    if (TuWenBlock[i]->strContent!=RichEdit1->Text)
        {
          TuWenBlock[i]->strContent = RichEdit1->Text;
        }
        this->Hide();
          return;  }
   TuWenBlock.push_back(pTuWenDesTemp);
   this->Hide();}查看的时候pTuWenDesTemp 有值,但是 TuWenBlock.push_back(pTuWenDesTemp);执行完成后, TuWenBlock.size() 为0,这是为什么啊,,,,

解决方案 »

  1.   

    1、 没有看到你在哪里测试size()大小?
    2、 你多个地方return,没有进行delete操作?不知道你用的环境是不是不需要new对应的delete?
      

  2.   

    我觉得问题1的测试size大小这个没有必要吧,比如说在for循环中,size返回0或者其他大于0的数,所以这个不影响程序的影响。 至于 new之后的确是需要delete,return之前的确是需要释放内存。最后还需要说一些,pTuWenDesTemp对应的内存块是有内容的,所以push_back函数执行完成后检查其size为0的确没有道理啊,,,,,,,,,,,