关于c++的一个报错
使用tstring构造函数,用到了VarBaseString的tostring,调用完,会导致局部对象指针为nullptr,目前在查原因
class VarBaseString : public Var { public: VarBaseString(std::string str = "") { val = str; type = "string"; } VarBaseString(const char* str) { val = str; type = "string"; } ~VarBaseString() { } static std::string GetType() { return "string"; } virtual std::string ToString() { return std::move(val); } VarBaseString operator =(const char* src) { val = src; return *this; } VarBaseString operator =(std::string src) { val = src; return *this; } std::string val; };
接下来是:
Control* ctrl = CreateControl(ele->Value()); /*if (strcmp(ele->Value(), "Widget") == 0) { Widget* wi = (Widget*)ctrl; wi->ParseXmlElement(ele); }*/ ctrl->ParseXmlElement(ele); TiXmlAttribute* ta = ele->FirstAttribute(); while (ta) { ctrl->SetAttribute(ta->Name(), ta->Value()); /* if (strcmp(ta->Name(), "pos") == 0) { int x, y; sscanf_s(ta->Value(), "%d,%d", &x, &y); ctrl->pos.x = x; ctrl->pos.y = y; } else if (strcmp(ta->Name(), "size") == 0) { int w, h; sscanf_s(ta->Value(), "%d,%d", &w, &h); ctrl->size.x = w; ctrl->size.y = h; } else if (strcmp(ta->Name(), "name") == 0) { sCtrlName = ta->Value(); }*/ /*else if (strcmp(ta->Name(), "bkcolor") == 0 || strcmp(ta->Name(), "bkclr") == 0) { sCtrlName = ta->Value(); int w, h; ctrl->size.x = w; ctrl->size.y = h; } else if (strcmp(ta->Name(), "hovercolor") == 0 || strcmp(ta->Name(), "hoverclr") == 0) { UITheme:: }*/ ta = ta->Next(); } TString sCtrlName(ctrl->name.val); if (ctrl) { childs.push_back(std::make_pair(TString(ctrl->name), ctrl)); //childs.push_back(std::make_pair("sCtrlName", ctrl)); } ele = ele->NextSiblingElement(); }