n0bra1n3r / cinterop

A C/C++ interop library for the Nim programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How do you deal with inheritance

mantielero opened this issue · comments

I have the following inheritance tree:

where I have the following code:

csource "BRepBuilderAPI_Transform.hxx":
  type
    BRepBuilderAPI_Transform* = object of CClass

  converter toTopoDS_Shape*(self: BRepBuilderAPI_Transform):TopoDS_Shape {.importcpp:"(#)".}

How would you call a method from BRepBuilderAPI_MakeShape given than Nim doesn't have multiple inheritance?

Multiple inheritance can be mimicked using converters + single inheritance + cexpr^ in most cases. converters + single inheritance takes care of implicit conversion between related types, and cexpr^ takes care of accessing inherited fields.

In the worst case scenario, you may have to write your own C++ to wrap functionality that can be translated to Nim via cinterop.

Yes. I used cexpr^ and it simply worked. Thanks.