c++ class constructor

December 13, 2010 at 13:21:24
Specs: Windows XP, 2 GB
please see my code below...I'm using Visual C++ 2008 Express Edition
I'm trying to parse an XML file using TinyXML. I have a class called buildConfig that I'm instantiating in my main function but I keep getting this error:
error C2512: 'TiXmlHandle' : no appropriate default constructor available
I have pointed out in code below where the error is

Please help...thanks

// compile with: /clr
// compile with: /W3
#include <vector>
#include <fstream>
#include <string>

#include <windows.h>
#include "tinyxml.h"

using namespace std;

class buildConfig
buildConfig(string xmlFile) // <- this is where the error is
configFile = xmlFile;

// destructor

bool parseBuildFile();

// Tiny XML document handlers
string configFile;
bool loadOkay;
TiXmlDocument doc;
TiXmlHandle docHandle;


bool buildConfig::parseBuildFile()
loadOkay = false;
TiXmlDocument readdoc(configFile.c_str()); // load build configuration xml file
TiXmlHandle readdocHandle( &readdoc ); // Load XML file into document handler

if(readdoc.LoadFile()) // check for load successful or fail
loadOkay = true;
doc = readdoc;
docHandle = readdocHandle;

return loadOkay;


#include <iostream>
#include <fstream>
using namespace std;

#include "buildConfig.h"

int main(int argc, char* argv[])
char* param = argv[1];
buildConfig build(param);
return 0;

See More: c++ class constructor

Report •

December 13, 2010 at 13:22:21
Another addition to my previous post...I do have a private string configFile

Report •

December 13, 2010 at 21:33:45
Disclaimer: I haven't used TinyXML, and I haven't looked at its documentation past TiXmlHandle (TiXmlNode *_node)'s one line of documentation, so I'm not going to spot any misuse of the classes.

buildConfig(string xmlFile) // <- this is where the error is
Yes and no. The actual reason is a bit further down, on the line TiXmlHandle docHandle;. Like the error says, TiXmlHandle doesn't have a parameter-less constructor, so we must give your docHandle a parameter. Try:

buildConfig(string xmlFile) : docHandle(0)

Infact, we could probably refactor your constructor to this line:
buildConfig(string xmlFile) : docHandle(0), configFile(xmlFile) { }

How To Ask Questions The Smart Way

Report •

December 14, 2010 at 15:37:00
thanks Razor..it worked

What is this type of constructor declaration called?

Report •

Related Solutions

December 14, 2010 at 16:37:30

Report •

Ask Question