I created a header with the dll settings:
globaldef.h
#pragma once
#ifdef OPENXML_LIB
#define OPENXML __declspec(dllexport)
#else
#define OPENXML __declspec(dllimport)
#endif // OPENXML_LIB
I've created two classes so far:
xmldoc.h
#pragma once
#define XML_MODE_R 0
#define XML_MODE_RW 1
#include "globaldef.h"
#include <fstream>
#include <string>
class OPENXML XmlDocumment {
public:
XmlDocumment(std::string fileName, int mode);
~XmlDocumment();
//Load xml content to string
virtual std::string read();
private:
//Xml file
std::fstream xmlFile;
std::string filename;
int mode = 0;
};
xmldoc.cpp
#include "stdafx.h"
#include "xmldoc.h"
XmlDocumment::XmlDocumment(std::string fileName, int mode) {
this->filename = fileName;
this->mode = mode;
}
XmlDocumment::~XmlDocumment() { }
std::string XmlDocumment::read() {
switch (mode) {
case XML_MODE_R: xmlFile.open(filename, std::ios::in); break;
case XML_MODE_RW: break;
}
std::string content((std::istreambuf_iterator<char>(xmlFile)), (std::istreambuf_iterator<char>()));
xmlFile.close();
return content;
}
And the other class at the time did not start writing
xmlnode.h
#pragma once
#include "globaldef.h"
class OPENXML XmlNode {
public:
};
Everything compiles normally if there is no constructor, but if you add a constructor even without some or empty parameters, the compiler issues the following error: