Reputation: 6459
In the constructor of an object I have the following code:
ConfigReader::ConfigReader(){
TiXmlDocument doc(CONFIGURATION_FILE_LOCATION);
configDoc = TiXmlHandle(&doc);
}
When I try to compile I get the following warning:
no matching funciton for call to 'TiXmlHandle::TiXmlHandle();
configDoc
is a TiXmlHandle
defined in my h-file as a private variable for the class. Both of the classes are from the TinyXML C++ project, but that's hardly relevant. The compiler is correct that there is no default constructor for TiXmlHandle
. However, since I'm constructing the TiXmlHandle using a valid constructor this, in theory, shouldn't matter.
So what is the syntax, if any, to tell C++ to not bother trying to create the TiXmlHandle
with a default constructor since I'm just going to override it?
I appologize for the simple question, I know that this is the sort of thing I should be able to look up but I've tried and not been able to stumble upon the answer.
Upvotes: 0
Views: 123
Reputation: 28178
configDoc
is being default constructed and then, later, you are trying to copy assign it to TiXmlHandle(&doc)
. A TiXmlHandle
apparently can't be default constructed, so this doesn't work. The default construction is happening implicitly because you haven't overridden it by using the member initialization list.
You use the member initialization list like so:
ConfigReader::ConfigReader()
: configDoc(/*args*/)
{
// ...
}
Obviously, to pass the proper argument to configDoc
in that location you'll have to restructure your code a bit. Perhaps your TiXmlDocument
should be a member too. There are a lot of refactoring options; You can figure that part out yourself.
Upvotes: 3