// ab.cpp
#include
class Test {
public:
Test(int);
~Test();
void set(int);
void print();
private:
int a;
};
Test::Test(int number) {
this->set(number);
}
Test::~Test() {
std::cout << "调用析构器" << std::endl;
}
void Test::set(int number) {
this->a = number;
}
void Test::print() {
std::cout << this->a << std::endl;
}
c++
编译为ab.obj
.
// test.d
extern(C++) {
class Test {
final this(int);
final ~this();
final void set(int);
final void print();
}
}
void main() {
import cppnew : CPPNew;
import cppnew : CPPDelete;
auto test = CPPNew!Test(67);
test.print(); //
test.set(12);
test.print(); //
CPPDelete(test); //
}
命令:
dmd -i % ab.obj
打印输出:
67
12
调用析构器