I am trying to create a configuration class which reads the data from an xml with rapidxml.
Therefore I have a private xml_document
which I parse inside of the constructor:
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();
}
Inside of the wWinMain
I create an config opject and try to call the methods.
Config* config = new Config();
LOG(config->findNode("width")->value()); // this does create violation reading
BUT if I put the same line into the constructor of the Config class it works without any problem. What is going wrong here?