How to repeat structure C++
MGW via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 15 23:27:50 PST 2017
On Monday, 16 January 2017 at 00:07:44 UTC, Adam D. Ruppe wrote:
> That's just interfaces and classes in D, so change struct to
> those words and go fro there.
// ------- jd.d: compile: dmd -c jd
import std.stdio;
extern (C++) interface IHome { int sum(int, int); };
extern (C++) void printIHome(void* ptr) {
IHome ob = cast(jd.IHome)ptr;
ob.sum(4, 5);
}
// ------- jc.cpp compile: dmc jc.cpp jd.obj phobos.lib
#include <stdio.h>
struct IHome {
int sum(int a, int b) {
int s = a+b; printf("a = %d, b = %d, sum = %d\n", a, b, s);
return s;
}
};
extern "C" int rt_init();
extern "C" int rt_term();
extern void printIHome(void*);
void main() {
IHome iMyHome;
rt_init();
// -------
iMyHome.sum(2, 3); // Call C++ method in C++
IHome* ptriMyHome = &iMyHome;
printIHome(ptriMyHome); // Call C++ method in D --> ERROR :-(
// -------
rt_term();
}
// ---- compile ------------------------------------------
dmd -c jd
dmc jc.cpp jd.obj r:\dmd2\windows\lib\phobos.lib
// -------------------------------------------------------
Please, help to rewrite jd.d for the correct method call in
structure ะก++.
More information about the Digitalmars-d-learn
mailing list