Dynamic Type in CxxWrap.jl

@barche helped me over at GitHub with this issue, the solution is as follows:

You have to define the type hierarchy in the jlcxx namespace, so add

namespace jlcxx
{
  template<> struct SuperType<DerivedA> { typedef Parent type; };
  template<> struct SuperType<DerivedB> { typedef Parent type; };
}

to the C++ code.

Then you can just try to manually convert the return value to the corresponding dynamic type on the julia side:

a = make_a()
# CxxPtr{Parent}(Ptr{Parent}(0x00007f7ac6869310))

# works as expected
a2 = convert(CxxPtr{DerivedA}, a)
# CxxPtr{DerivedA}(Ptr{DerivedA}(0x00007f7ac6869310))

# conversion to the wrong type fails and returns a null pointer
ab = convert(CxxPtr{DerivedB}, a)
# CxxPtr{DerivedB}(Ptr{DerivedB}(0x0000000000000000))

ab == C_NULL
# true