xml에서 rapidxml을 사용하여 데이터를 읽는 구성 클래스를 만들려고합니다. 그러므로 내가 생성자의 내부 분석 개인 xml_document
이 다음 wWinMain
의 내부다른 클래스에서이 메서드를 호출하면 위반 읽기가 발생합니다.
class Config
{
public:
Config();
~Config();
/*returns the first found node*/
xml_node<>* findNode(const char* name);
/*get an configuration value. It's always a char*/
char* getConfigValue(const char* name);
private:
rapidxml::xml_document<>* m_doc;
};
//cpp
Config::Config()
{
m_doc = new xml_document<>();
rapidxml::file<> xmlFile("config.xml");
m_doc->parse<0>(xmlFile.data());
//LOG(getConfigValue("width")); // here it works
}
xml_node<>* Config::findNode(const char* name)
{
return m_doc->first_node()->first_node(name);
}
char* Config::getConfigValue(const char* name){
return m_doc->first_node()->first_node(name)->value();
}
가 나는 구성 opject를 생성하고 메소드를 호출하려고합니다.
Config* config = new Config();
LOG(config->findNode("width")->value()); // this does create violation reading
하지만 Config 클래스의 생성자에 같은 줄을 입력해도 문제없이 작동합니다. 여기서 뭐가 잘못 됐어?
것 같습니다 :
그래서 당신이 정말로 원하는이 같은 것입니다. – user657267
'm_doc = new xml_document <>();'를 ctor에 추가하면 뭔가 변경됩니다. – BennX
아마도'm_doc'은 사용하기 전에 뭔가를 지적해야합니다. – user657267