I try to overload a protected function of one of my XML class.
In short, there are the C_XmlArrayField<T> which help saving std::list<T> objects, with primitive type (or type with a operator>> with std::*stringstream). And I've got C_XmlClassArrayField<T> which do the same thing, but with class inheriting for the C_XmlBasicObject class (which is an abstract class with two method, one for saving the instance into a XML element, and another for loading the instance from an XML element).
So, the C_XmlArrayField<T> have the writing and reading function, and a writeItem and a readItem virtual function, which use std::*stringstream for writing/reading a single item. The C_XmlClassArrayField<T> is declared in this way :
template<T>
class C_XmlClassArrayField : public C_XmlArrayField<T*>
{ ... blabla ... }
I give you the two files :
- For the
C_XmlArrayField<T>: http://ift.tt/2afDYGL - For the
C_XmlClassArrayField<T>: http://ift.tt/2a32w2h
So, this is my problem :
I overloaded the writeItem and the readItem for C_XmlClassArrayField<T> but, this give me an error when I try to use is with a testing class (which inherit from C_XmlBasicObject) :
Libraries/ns_framework/Headers/ns/xml/C_XmlArrayField.hpp:203:7: error: no match for 'operator>>' (operand types are 'std::istringstream {aka std::__cxx11::basic_istringstream<char>}' and 'Test*')
I don't understand because I overloaded the virtual function within C_XmlClassArrayField<T>.
Finally, my test code :
#include <iostream>
#include <ns/xml.hpp>
#include <ns/scene.hpp>
#include <ns/anim.hpp>
#include <ns/utils.hpp>
using namespace std;
using namespace ns;
using namespace tinyxml2;
// C_XmlObject inherits from C_XmlBasicObject.
class Test : public C_XmlObject
{
public:
Test(string name="test") :
C_XmlObject(name)
{
addField<int>("int").set(42);
}
};
int
main (int argc, char** argv)
{
C_XmlClassArrayField<Test> array("test");
array->push_back(new Test());
array->push_back(new Test());
XMLDocument doc;
auto root = doc.NewElement("root");
doc.InsertFirstChild(root);
array.write(doc, root);
doc.Print();
return 0;
}
Did I miss something with the templates ?
Thanks for your answers !
Aucun commentaire:
Enregistrer un commentaire