I am trying to wrap a function which is used to cast to another type.

The C++ example is:
    
    
    ++
    Handle(Geom_Point) aPnt1;
    Handle(Geom_CartesianPoint) aPnt2, aPnt3;
    aPnt2 = new Geom_CartesianPoint();
    aPnt1 = aPnt2; // OK, standard assignment
    aPnt3 = Handle(Geom_CartesianPoint)::DownCast (aPnt1);
    // OK, the actual type of aPnt1 is Geom_CartesianPoint, although the static 
type of the handle is Geom_Point
    
    
    Run

where `Geom_CartesianPoint` inherits from `Geom_Point`. And `Handle` is some 
form of smart pointer. (Sorry, if the terminology is not correct, since I am 
not a pro).

In the header file, there are two functions defined as follows:
    
    
    ++
        //! Down casting operator from handle to base type
        template <class T2>
        static typename opencascade::std::enable_if<is_base_but_not_same<T2, 
T>::value, handle>::type
          DownCast (const handle<T2>& theObject)
        {
          return handle (dynamic_cast<T*>(const_cast<T2*>(theObject.get())));
        }
        
        //! Down casting operator from pointer to base type
        template <class T2>
        static typename opencascade::std::enable_if<is_base_but_not_same<T2, 
T>::value, handle>::type
          DownCast (const T2* thePtr)
        {
          return handle (dynamic_cast<T*>(const_cast<T2*>(thePtr)));
        }
    
    
    Run

What I tried something as the following in several forms:
    
    
    proc downcast*[T; T2](this: Handle[T] ): Handle[T2] {.cdecl,
        importcpp: "Handle('0)::Downcast(@)", header: "Standard_Handle.hxx".}
    
    
    Run

but when I compile I get:
    
    
    Error: cannot instantiate: 'T2'
    
    
    Run

How can I fix this?

Reply via email to