http://d.puremagic.com/issues/show_bug.cgi?id=2480


[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[EMAIL PROTECTED]
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Comment #1 from [EMAIL PROTECTED]  2008-11-30 14:54 -------
That's not supposed to work, see
http://www.digitalmars.com/d/2.0/cpp_interface.html.  Scroll down to "Calling
C++ Virtual Functions From D" on that page.  C++ functions have to be either
global or virtual, and you need to create an interface on the D side.  C++
struct virtual methods won't work, since the name mangling is different than
for classes.  And you need to instantiate and delete C++ objects in C++ code,
not D code.

This works, at least on Windows:

foo.cpp file:
class Board{ public: virtual void clear(){} };

Board* createBoard() { return new Board; }
void freeBoard(Board* b) { delete b; }


bar.d file:
extern(C++) interface Board
{
    void clear();
}

extern (C++) Board createBoard();
extern (C++) void freeBoard(Board b);

void main()
{
  Board b = createBoard();
  b.clear();
  freeBoard(b);
}


-- 

Reply via email to