我在全局或一个对话框类里定义了一个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);}
现在只能增加一个元素,再加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);}
如果里面涉及自己管理的内存等在内的话,你需要为str_origdata实现copy constructor和assignment operator,以实现deep copy!
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吗?请大侠详细说说
你的错误估计不是因为vector的问题,而是你的origdata=get_origdata(cday,thunder); 或者类似的地方出的问题
你查一下别的地方看看。
struct str_origdata CStaDlg::get_origdata(int cday,struct str_thunder thunder)
{
struct str_origdata orig;
...... //为orig的各个成员赋值 return orig;
}
也确实传到了数组bdata里,但加第二次就
直接给终止了