你好我有以下功能:
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);
}
我认为我有内存泄漏,返回后如何删除指针?如何使用析构函数来释放内存我得到一个运行时错误 bad:alloc