I am trying to write a class to parse XML documents. This is the header file:
using namespace std;
class xmlHelper {
public:
xmlHelper();
virtual ~xmlHelper();
private:
xmlpp::DomParser parser;
};
The code looks like this:
#include "xmlHelper.h"
xmlHelper::xmlHelper()
{
}
xmlHelper::~xmlHelper()
{
}
Compiling fails with these errors:
error: use of deleted function ‘xmlHelper::xmlHelper(const xmlHelper&)’
error: use of deleted function ‘xmlpp::Parser::Parser(const xmlpp::Parser&)’
error: use of deleted function ‘xmlpp::NonCopyable::NonCopyable(const xmlpp::NonCopyable&)’
Moving the line xmlpp::DomParser parser;
from the header file to the constructor, the code compiles.
I want to use a private variable which holds the XML document. What do I have to do to create such a variable?
Thx
Your class is probably being copied somewhere (std::vector containee perhaps?) and the xmlpp::Parser
object does not allow copying.
When you have a class that allows copying/moving, all the members inside the class have to have non-deleted copy/move constructors or operator =s (either default or explicitly defined, but not deleted).
Use std::shared_ptr<xmlpp::Parser>
instead.