digitalmars.D.learn - C++ Interop -- Two Questions
- Mike Parker (13/13) Sep 09 2015 Given a C++ class that looks like this:
- Mike Parker (2/3) Sep 09 2015 [1] http://dlang.org/cpp_interface.html
- Jacob Carlborg (8/21) Sep 09 2015 The documentation for the C++ support is very outdated. I recommend to
- Kagamin (3/3) Sep 09 2015 Static functions are declared with `static` storage class. This
- Mike Parker (11/14) Sep 09 2015 Yes, I get that. But how does that work when you're linking to a
- Kagamin (8/16) Sep 09 2015 Classes and templates except for special members (which are
Given a C++ class that looks like this: class Foo { static void Initialize(const SomeObject&); virtual void func1(); } The documentation at [1] doesn't say anything about how to handle static member functions like Initialize, nor do I see anything about references. I assume I can declare any reference function parameters using D's ref, but I have no idea how to declare static methods. My questions: 1) Am I right about ref? 2) Do I need to create a wrapper function in C or C++ for static member functions?
Sep 09 2015
On Wednesday, 9 September 2015 at 09:55:21 UTC, Mike Parker wrote:The documentation at [1] doesn't say anything about how to[1] http://dlang.org/cpp_interface.html
Sep 09 2015
On 2015-09-09 11:55, Mike Parker wrote:Given a C++ class that looks like this: class Foo { static void Initialize(const SomeObject&); virtual void func1(); } The documentation at [1] doesn't say anything about how to handle static member functions like Initialize, nor do I see anything about references. I assume I can declare any reference function parameters using D's ref, but I have no idea how to declare static methods. My questions: 1) Am I right about ref?I would assume so. It's just a pointer under the hood.2) Do I need to create a wrapper function in C or C++ for static member functions?The documentation for the C++ support is very outdated. I recommend to give it a try and see what happens :). Alternatively look in the DMD test suite and see what you can find, or the DMD source code now when it's in D. -- /Jacob Carlborg
Sep 09 2015
Static functions are declared with `static` storage class. This looks so basic, it's even not documented in language spec, lol. In D classes are reference types by default.
Sep 09 2015
On Wednesday, 9 September 2015 at 11:49:33 UTC, Kagamin wrote:Static functions are declared with `static` storage class. This looks so basic, it's even not documented in language spec, lol.Yes, I get that. But how does that work when you're linking to a C++ library and the translation of the C++ class to D is an interface? Or is it possible now to link D classes directly with C classes?In D classes are reference types by default.Yes, of course. I just want to verify that the D ref and C++ ref are equivalent. I realize I can do it myself when I sit down this weekend and start exploring it, but I'm hoping someone can point me to a blog post, some sample code, or just give me some insights to save time.
Sep 09 2015
On Wednesday, 9 September 2015 at 13:17:53 UTC, Mike Parker wrote:Yes, I get that. But how does that work when you're linking to a C++ library and the translation of the C++ class to D is an interface? Or is it possible now to link D classes directly with C classes?Classes and templates except for special members (which are usually relied upon heavily in C++ code, but maybe your C++ code is unusual).I realize I can do it myself when I sit down this weekend and start exploring it, but I'm hoping someone can point me to a blog post, some sample code, or just give me some insights to save time.You can see bugzilla issues marked with C++ keyword. The docs were deemed unworthy because of skills required to write C++ bindings. Maybe because it's still not practical as it doesn't support critical C++ idioms like RAII.
Sep 09 2015