你好,我有以下功能:刪除指針
Block* Keywords::parseBlock(TiXmlElement* element)
{
double x1 = atoi(element->Attribute("left"));
double y1 = atoi(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
double width = abs(x2 - x1);
int bid = atoi(element->Attribute("id"));
vector<LineElement*> lines;
for (TiXmlElement* sub = element->FirstChildElement("line"); sub; sub = sub->NextSiblingElement("line"))
lines.push_back(parseLine(sub));
return new Block(y2,x2,y1,x1,bid,width, lines);
}///End function parse Block
LineElement* Keywords::parseLine(TiXmlElement* element)
{
double x1 = atoi(element->Attribute("left"));
double y1 = atof(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
int bid = atoi(element->Attribute("id"));
vector<Element*> words;
for (TiXmlElement* sub = element->FirstChildElement("word"); sub; sub = sub->NextSiblingElement("word"))
words.push_back(parseWord(sub));
return new LineElement(y2,x2,y1,x1,bid,words);
}///End function parse Line
Element * Keywords::parseWord(TiXmlElement* element)
{
string w =element->Attribute("value");
double x1 = atoi(element->Attribute("left"));
double y1 = atoi(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
int bid = atoi(element->Attribute("id"));
vector<Letter*> chars;
for (TiXmlElement* sub = element->FirstChildElement("char"); sub; sub = sub->NextSiblingElement("char"))
chars.push_back(parseChar(sub));
return new Element(w,y1, x1, y2,x2,-1,bid,chars);
}///End function parse word
Letter * Keywords::parseChar(TiXmlElement* element)
{
string w = element->Attribute("value");
double x1 = atoi(element->Attribute("left"));
double y1 = atoi(element->Attribute("top"));
double x2 = atoi(element->Attribute("right"));
double y2 = atoi(element->Attribute("bottom"));
int bid = atoi(element->Attribute("id"));
return new Letter(w,y1,x1,y2,x2,bid);
}
我認爲我有內存泄漏,我怎樣才能回國後將其刪除指針? 如何使用析構函數釋放內存我遇到了運行時錯誤:alloc
@vidit不,我沒有錯誤是:通過像'gdb'調試扔「的std :: bad_alloc的」 –
運行此實例,所以你可以計算出它墜毀後終止通話。 –
註冊新類型:wxString 註冊新類型:STL字符串 註冊新類型:STL矢量 設置斷點 調試器名稱和版本:GNU GDB(GDB)7.5 子進程PID:6316 程序接收信號SIGTRAP,跟蹤/斷點陷阱。 (c:\ Windows \ system32 \ ntdll.dll) #15 0x0043d519 in __gnu_cxx :: new_allocator :: deallocate(this = 0x28f684,__p = 0xa90460)在c:/ mingw/bin /中。 ./lib/gcc/mingw32/4.6.2/include/c++/ext/new_allocator.h:98 C:包括\ C++ \分機\ new_allocator.h:98:3034:BEG:0x43d519 在C:\ MinGW的\ LIB \ GCC \的mingw32 \ 4.6.2 \包括\ C++ \分機\ new_allocator.h:98 –