View previous topic :: View next topic |
Author |
Message |
flashdog
Joined: 10 Oct 2008 Posts: 15
|
Posted: Thu Nov 13, 2008 6:26 am Post subject: Call C++ from D |
|
|
Hello,
how can I call this C++ Code from D ?
Code: |
class Shape {
public:
Shape() {
nshapes++;
}
virtual ~Shape() {
nshapes--;
};
double x, y;
void move(double dx, double dy);
virtual double area(void) = 0;
virtual double perimeter(void) = 0;
static int nshapes;
};
class Circle : public Shape {
private:
double radius;
public:
Circle(double r) : radius(r) { };
virtual double area(void);
virtual double perimeter(void);
};
class Square : public Shape {
private:
double width;
public:
Square(double w) : width(w) { };
virtual double area(void);
virtual double perimeter(void);
};
|
Code: |
#include "example.h"
#define M_PI 3.14159265358979323846
/* Move the shape to a new location */
void Shape::move(double dx, double dy) {
x += dx;
y += dy;
}
int Shape::nshapes = 0;
double Circle::area(void) {
return M_PI*radius*radius;
}
double Circle::perimeter(void) {
return 2*M_PI*radius;
}
double Square::area(void) {
return width*width;
}
double Square::perimeter(void) {
return 4*width;
}
|
Best regards |
|
Back to top |
|
|
deadimp
Joined: 22 Oct 2008 Posts: 28
|
Posted: Thu Nov 13, 2008 1:14 pm Post subject: |
|
|
You can either look into some of the C++ binding utilities there are on DSource, or generate C bindings (using either a tool or just on your own). _________________ deadimp.org
> MegaMan X Crossfire - MegaMan X fan game
Beginning D; Basic experience in PHP, C++, Java, C#, MySQL, HTML, CSS, JavaScript, VB |
|
Back to top |
|
|
flashdog
Joined: 10 Oct 2008 Posts: 15
|
Posted: Thu Nov 13, 2008 6:08 pm Post subject: |
|
|
* ForC++ binding utilities you mean BCD?
* Which tool generate C bindings of a C++ code?
* Exist somewhere a howto how I can create C bindings for C++ Code? |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Thu Nov 13, 2008 6:25 pm Post subject: |
|
|
You have to create a Glue library in C that calls the C++ functions you want. You can then call the C function from D. |
|
Back to top |
|
|
flashdog
Joined: 10 Oct 2008 Posts: 15
|
Posted: Thu Nov 13, 2008 6:31 pm Post subject: |
|
|
But how can I creat a Glue library in C that calls the C++ functions?
Do you know where I can find howto to create a Glue library? |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Fri Nov 14, 2008 9:47 am Post subject: |
|
|
You use a C++ compiler and do things like...
Code: |
c_function(...)
{
// Call C++ code
C++_code_here();
}
| [/code] |
|
Back to top |
|
|
3-S-E
Joined: 16 Jun 2008 Posts: 54
|
|
Back to top |
|
|
|