digitalmars.D.bugs - [Issue 12854] New: Cannot interface to C++ code with const class
- via Digitalmars-d-bugs (28/28) Jun 04 2014 https://issues.dlang.org/show_bug.cgi?id=12854
https://issues.dlang.org/show_bug.cgi?id=12854 Issue ID: 12854 Summary: Cannot interface to C++ code with const class pointers Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Severity: normal Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: atila.neves gmail.com D: extern(C++) interface DClass { int getIndex() const; } extern(C++) void useObj(in DClass dclass); //I also tried const DClass C++: struct DClass { virtual int getIndex() const = 0; } void useObj(const DClass* dclass); //DClass* works though! The code above refuses to link. Whether not the D declaration for useObj is marked `const`, or `in` makes no difference, either way the C++ declaration can't have const in it. OTOH, if instead it's `ref const(DStruct)` and `const DStruct&` (or the equivalent pointer declarations it links fine. I'm aware of the differences between const in C++ and D, but the above makes it worse: D can happily think it's const while the C++ code is free to do whatever it wants without even having to use const_cast. --
Jun 04 2014