在MFC中为什么我new了对象,但用delete却总是报错呢?
new了之后要delete总是报错TiXmlDocumentGrammar;TiXmlElement*define=newTiXmlElement("DEFINE");r...
new 了之后 要delete总是报错
TiXmlDocument Grammar;
TiXmlElement *define = new TiXmlElement("DEFINE");
root->LinkEndChild(define);
TiXmlElement *ids = new TiXmlElement("ID");
ids->SetAttribute("NAME",SCmd);
ids->SetAttribute("VAL",char_Val);
define->LinkEndChild(ids);
TiXmlElement *rule = new TiXmlElement("RULE");
rule->SetAttribute("NAME",LCmd);
rule->SetAttribute("ID",SCmd);
rule->SetAttribute("TOPLEVEL","ACTIVE");
root->LinkEndChild(rule);
TiXmlElement *L = new TiXmlElement("L");
rule->LinkEndChild(L);
TiXmlElement *P = new TiXmlElement("P");
P->LinkEndChild(new TiXmlText(ChiCmd));
L->LinkEndChild(P);
Grammar.SaveFile("res\\CmdGrammar.xml");
Grammar.Clear();
/*delete decl;
delete root;
delete define;
delete ids;
delete rule;
delete L;
delete P;*/
delete后就报错 展开
TiXmlDocument Grammar;
TiXmlElement *define = new TiXmlElement("DEFINE");
root->LinkEndChild(define);
TiXmlElement *ids = new TiXmlElement("ID");
ids->SetAttribute("NAME",SCmd);
ids->SetAttribute("VAL",char_Val);
define->LinkEndChild(ids);
TiXmlElement *rule = new TiXmlElement("RULE");
rule->SetAttribute("NAME",LCmd);
rule->SetAttribute("ID",SCmd);
rule->SetAttribute("TOPLEVEL","ACTIVE");
root->LinkEndChild(rule);
TiXmlElement *L = new TiXmlElement("L");
rule->LinkEndChild(L);
TiXmlElement *P = new TiXmlElement("P");
P->LinkEndChild(new TiXmlText(ChiCmd));
L->LinkEndChild(P);
Grammar.SaveFile("res\\CmdGrammar.xml");
Grammar.Clear();
/*delete decl;
delete root;
delete define;
delete ids;
delete rule;
delete L;
delete P;*/
delete后就报错 展开
4个回答
展开全部
那就可能是你的new运算符操作失败了。
对于空指针当然不能delete
一般都是调用delete之前先对指针进行有效性检验:ASSERT(p)/ASSERT_VALID(p)之类的。
然后在delete.防止同一对象被delete多次或者对空对象delete
希望对你有所帮助!
对于空指针当然不能delete
一般都是调用delete之前先对指针进行有效性检验:ASSERT(p)/ASSERT_VALID(p)之类的。
然后在delete.防止同一对象被delete多次或者对空对象delete
希望对你有所帮助!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是delete 到第几个出错的.
检查指针是否为空.
检查指针是否为空.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询