Hi, I try to subclass a C++ class in nim and implement some features in nim. Here is what I do:
{.emit:"""
class Foo {
public:
int data;
Foo() {}
};
class Bar: public Foo {
public:
int d2;
Bar() : Foo() {}
~Bar();
};
""".}
{.deadCodeElim: off.} # seems no to work
type
Foo* {.importcpp: "Foo", inheritable.} = object
data: cint
Bar* {.importcpp: "Bar".} = object of Foo
d2: cint
proc newBar(): ptr Bar {.importcpp:"new Bar()".}
proc cdelete*[T](x: ptr T) {.importcpp: "delete #", nodecl.}
proc killBar() {.codegenDecl: "Bar::~Bar$3", used, exportc.} =
var self {.noInit.}: ptr Bar
{.emit: "self = this;".}
echo "kill it ", self.d2
proc main() =
var f: Foo
var b = newBar()
b.d2 = 12
cdelete b
main()
the code actual compiles and runs, but there are some things I don't like:
proc killBar() {.codegenDecl: "Bar::~Bar$3", used, exportc.} =
var self {.importcpp: "this", nodecl, noInit.}: ptr Bar
#{.emit: "self = this;".}
echo "kill it ", self.d2
but this still produces a line with
Bar* this;
into the C++ code. the nodecl seems to be ignored here.
Has anybody some hints how to improve that ?