[Issue 2480] extern(C++) does not work with linux
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Nov 30 12:54:21 PST 2008
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=2480
torhu at yahoo.com changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torhu at yahoo.com
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID
------- Comment #1 from torhu at yahoo.com  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);
}
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list