mm: mm.obj cppnew.obj test.obj
link $^
mm.obj: mm.d
dmd -m32mscoff -c $^ $@
cppnew.obj: cppnew.d
dmd -m32mscoff -c $^ $@
test.obj: test.cpp
clang++ -o $@ -c $^
犯了很多错.这样就可以了.
// mm.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(); // will print 67
test.set(12);
test.print(); // will print 12
CPPDelete(test); // will print Destructor called
}
//test.cpp
#include <iostream>
class Test {
public:
Test(int);
~Test();
void set(int);
void print();
private:
int a;
};
Test::Test(int number) {
set(number);
}
Test::~Test() {
std::cout << "diaoyong xg" << std::endl;
}
void Test::set(int number) {a = number;}
void Test::print() {
std::cout <<a<< std::endl;
}
cppnew
在此.