[xsd-users] [xsd] Polymorphism dynamic_cast returns 0.

Harg Tholan hargtholan at gmail.com
Fri Sep 13 10:39:34 EDT 2013


Hi,



I started a re-factor in my project aiming to replace the "xs:choice
polymorphism" with proper XML polymorphism (xsi:type), the dynamic casting
fails to retrieve the actual type. I am using "--generate-polymorphic", and
even specifying the base types with "--polymorphic-type". In section 5.4 of
the manual it is mentioned this: " [...] as well as pass true as the last
argument to the xml_schema::document's constructors.", but I do not know
how to call such constructor. I am instantiating my objects this way:

std::auto_ptr<xml:foo::Obj> obj(xml::foo::Obj(argv[1],xml_schema::flags::
dont_validate));

then I perform the dynamic type checking like:

if (xml::foo::ConcreteBar* c = dynamic_cast<xml::foo::ConcreteBar*> (&(*
itr)))

(where itr is an iterator of a sequence of base type elements).

I inspected the generated code and looks fine (ConcreteBar inherits from
public Bar). What am I doing wrong?
Thanks.


More information about the xsd-users mailing list