Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
September 09, 2015 C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
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? |
September 09, 2015 Re: C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | 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 |
September 09, 2015 Re: C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | 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 |
September 09, 2015 Re: C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | 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. |
September 09, 2015 Re: C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kagamin | 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. |
September 09, 2015 Re: C++ Interop -- Two Questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | 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. |
Copyright © 1999-2021 by the D Language Foundation