So I manage to compile it. The code is: # nim cpp ex.nim {.passL: "-lTKG2d -lTKernel", passC:"-I/usr/include/opencascade" } discard "forward decl of gp_Pnt2d" discard "forward decl of gp_Trsf2d" discard "forward decl of Geom2d_Geometry" discard "forward decl of Geom2d_CartesianPoint" {.push header: "Geom2d_CartesianPoint.hxx"} type Standard_Real* {.importcpp: "Geom2d_CartesianPoint".} = cdouble #{.importcpp: "Geom2d_CartesianPoint" .} Geom2d_CartesianPoint* {.importcpp: "Geom2d_CartesianPoint", bycopy.} = object proc constructGeom2d_CartesianPoint*(X, Y: Standard_Real): Geom2d_CartesianPoint {. importcpp: "Geom2d_CartesianPoint(@)" .} {.pop.} # {.push header: "Geom2d_CartesianPoint.hxx"} proc cnew*[T](x: T): ptr T {.importcpp: "(new '*0#@)", nodecl.} let pnt = cnew constructGeom2d_CartesianPoint( (0.0).Standard_Real, (0.0).Standard_Real ) echo repr pnt Run
Which is a mix of what `c2nim` gave me and the [documentation](https://nim-lang.org/docs/manual.html#importcpp-pragma-importcpp-for-procs). * * * I have a question which is probably a C++ one rather than a Nim question. I used the constructor pragma which worked on OSG library but not with OpenCascade. Then I tried with something like this (which failed as well): proc newFoo(a, b: cint): ptr Foo {.importcpp: "new Foo(@)".} let x = newFoo(3, 4) Run and finally, I imported the `new` operator (which worked with OpenCascade): proc cnew*[T](x: T): ptr T {.importcpp: "(new '*0#@)", nodecl.} # constructor of 'Foo': proc constructFoo(a, b: cint): Foo {.importcpp: "Foo(@)".} let x = cnew constructFoo(3, 4) Run > The documentation says: "However, depending on the use case new Foo can also > be wrapped like this instead: ...." I don't really understand the difference between these three cases or three ways to wrap a constructor. Probably because I don't know C++. It looks like it is related to [this](https://stackoverflow.com/questions/6337294/creating-an-object-with-or-without-new), so I just keep this for others like me (hobby programmers who might find this thread). After I found my error, I checked that the following works: Geom2d_CartesianPoint *prueba = new Geom2d_CartesianPoint (0.0, 0.0) ; Run but the following doesn't: Geom2d_CartesianPoint *prueba = Geom2d_CartesianPoint (0.0, 0.0) ; Run