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

Harg Tholan hargtholan at gmail.com
Mon Sep 16 02:49:49 EDT 2013


Hi,

Thanks for your help, typeid (*itr).name() tells that the type is "Bar", in
my XML document I have instances of "ConcreteBar".

Thanks.


2013/9/13 Boris Kolpackov <boris at codesynthesis.com>

> Hi Harg,
>
> Harg Tholan <hargtholan at gmail.com> writes:
>
> > 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.
>
> That only applies to the C++/Parser mapping while you are using
> C++/Tree.
>
> > 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?
>
> Hm, if Bar is made polymorphic (with --polymorphic-type) and the actual
> type in XML is of the derived type (i.e., it either uses a substitution
> group or xsi:type), then everything should work fine. You don't seem
> to be slicing the object.
>
> You may want to print the name of the dynamic type and see what it
> reveals:
>
> cerr << typeid (*itr).name () << endl;
>
> If that doesn't help, can you show the relevant XML fragment?
>
> Boris
>


More information about the xsd-users mailing list