d的extern(C++)还有问题

import std.stdio;
extern(C++) class C {
    bool onStack;
    this(bool onStack) {
        this.onStack = onStack; 
    }
    ~this() {
        writeln("Destroying ", onStack? "stack" : "heap", " C instance."); 
    }
}
extern(D) class D {
    bool onStack;
    this(bool onStack) {
        this.onStack = onStack; 
    }
    ~this() {
        writeln("Destroying ", onStack? "stack" : "heap", " D instance."); 
    }
}

void main() {
    scope stackC = new C(true);
    auto heapC = new C(false);
    scope stackD = new D(true);
    auto heapD = new D(false);
}

已搞定.

posted @ 2021-03-11 10:48  zjh6  阅读(6)  评论(0)    收藏  举报  来源