c++ - how to release struct pointer elements after push_back into the vector -
hi every 1 having issue insertion of struct stuct vector... please see following codes
struct stline { double** ptrroadcords; int isize; };
//i having struc , vector is
std::vector<stline> m_vecstline;
//i creating temp struct
stline line; line.ptrroadcords = new double*[cnt]; ( int = 1; < cnt-1; i++ ) { line.ptrroadcords[i-1] = new double[2]; line.ptrroadcords[i-1][0] = ptrcords[i-1][0]; line.ptrroadcords[i-1][1] = ptrcords[i-1][1]; } m_vecstline.push_back(line);
//so working perfect causing meomory leaks
//so put releasing code
if (line.ptrroadcords != null) { (int = 0; < cnt-2; i++) { delete[]line.ptrroadcords[i]; } if(line.ptrroadcords) delete[]line.ptrroadcords; }
but because of application crashes because clears vector element because inserting refernce
please me resolve issue
thank u in advance
Comments
Post a Comment