我在全局或一个对话框类里定义了一个struct类型的动态数组,通过对话框向里面填数据。
现在只能增加一个元素,再加OS就放狗给终止了,这是为什么啊?
开始用的是CArry的add不行,现在改成vector的push_back也不行。
应该是我程序的问题,请大侠给看看。
我的程序简化一些是这样的:#include "stdafx.h"
#include "reverse.h"
#include "StaDlg.h"
#include "afxtempl.h"
#include "time.h"
#include "define.h"
#include <vector>
using std::vector;vector<str_origdata> bdata;   //定义一个动态数组void CStaDlg::OnStaadd() 
{
// TODO: Add your control notification handler code here
int cyear,cmonth,cday,chour,cminute,csecond;
struct tm timer,*tms;
time_t nowtime,ret_time;/***********在对话框的列表框内显示加入的基站信息**************************/
CString str,strtemp;
str=m_nStaname;
str+="站     ";
strtemp.Format("经度%4.4f     ",m_nStalong);
str+=strtemp; 
    strtemp.Format("纬度%4.4f     ",m_nStalat);
    str+=strtemp;
strtemp.Format("到达时间%2.7f ",m_nStatime);
str+=strtemp;
m_StaList.AddString(str);
UpdateWindow();/***********向基站安全数组添加元素***********************************/
                ......  ......                      //给cday和thunder赋值 origdata=get_origdata(cday,thunder);  //通过类的一个成员函数给origdata赋值
bdata.push_back(origdata);}

解决方案 »

  1.   

    str_origdata是怎么样定义的?
    如果里面涉及自己管理的内存等在内的话,你需要为str_origdata实现copy constructor和assignment operator,以实现deep copy!
      

  2.   

    str_origdata是一个结构体,里面只有一些数据成员,定义是这样的:
    struct str_origdata
    {
    int NID;
    int tyear;
    int tmonth;  //Date
    int tday;
    int thour;
    int tminute;
    int tsecond;
    long tius;
    long double ttime;

    double tbns;  //Physic
    double tbew;
    double tflashangle;
    double tbinten;
    double teinten; 
           
    double tbMsp;
    double tblinten;   /*zui da zhi fenliang */

    short tMsp_01us;  //Time
    short tPp_01us;
    short tHwp_01us;
    };
    里面没有自己管理的内存啊,是个普通的结构体
    需要deep copy吗?请大侠详细说说
      

  3.   

    你在debug模式下看看是什么异常,然后根据call stack来看看具体是什么地方的错误
    你的错误估计不是因为vector的问题,而是你的origdata=get_origdata(cday,thunder);  或者类似的地方出的问题
      

  4.   

    看了你的结构,不需要deep copy,那应该是其它的问题了。
      

  5.   

    不一定就是动态数组的问题,我看就这么操作STL不会出现问题。
    你查一下别的地方看看。
      

  6.   

    大家看看是不是origdata=get_origdata(cday,thunder);的问题
    struct str_origdata CStaDlg::get_origdata(int cday,struct str_thunder thunder)
    {
    struct str_origdata orig;

              ......         //为orig的各个成员赋值  return orig;
    }
      

  7.   

    我跟踪了一下,第一次origdata确实有值,
    也确实传到了数组bdata里,但加第二次就
    直接给终止了