digitalmars.D.learn - How to do "C++ classes"?
- rempas (6/6) Sep 18 2021 I'm seeing in the page about "BeterC" and in the part about the
- Adam D Ruppe (6/12) Sep 18 2021 extern(C++)
- rempas (3/15) Sep 19 2021 Works flawlessly! Thanks a lot!
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (5/17) Sep 20 2021 I thought it's stack-allocated and scoped. But when I try to
- Adam D Ruppe (9/12) Sep 20 2021 It is.
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (3/15) Sep 20 2021 That is what I thought too. I only tried this on the online
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/24) Sep 20 2021 I also think this is a dirty corner of the complier since it must
I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained says about "COM classes and C++ classes". What are the "C++ classes"? I tried to create a class using "extern(C++)" but this didn't worked. Can someone make an example on that?
Sep 18 2021
On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote:I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the classes"? I tried to create a class using "extern(C++)" but this didn't worked. Can someone make an example on that?extern(C++) class Foo {} void main() { scope Foo foo = new Foo(); }
Sep 18 2021
On Saturday, 18 September 2021 at 22:16:32 UTC, Adam D Ruppe wrote:On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote:Works flawlessly! Thanks a lot!I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the "C++ classes"? I tried to create a class using "extern(C++)" but this didn't worked. Can someone make an example on that?extern(C++) class Foo {} void main() { scope Foo foo = new Foo(); }
Sep 19 2021
On Saturday, 18 September 2021 at 22:16:32 UTC, Adam D Ruppe wrote:On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote:I thought it's stack-allocated and scoped. But when I try to return a class instance from a function, it still works? Captain Adam I need an explanation please.I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the "C++ classes"? I tried to create a class using "extern(C++)" but this didn't worked. Can someone make an example on that?extern(C++) class Foo {} void main() { scope Foo foo = new Foo(); }
Sep 20 2021
On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote:I thought it's stack-allocated and scoped.It is.But when I try to return a class instance from a function, it still works?dmd only makes that an error if you specify ` safe` and i think `-dip1000`. Try adding one or both of those and recompiling and see what happens. Note that even if the compiler doesn't error on it, it is undefined behavior to return the stack reference so be sure to treat it right.
Sep 20 2021
On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe wrote:On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote:That is what I thought too. I only tried this on the online compiler. Thank you. Have a great day or night captain.I thought it's stack-allocated and scoped.It is.But when I try to return a class instance from a function, it still works?dmd only makes that an error if you specify ` safe` and i think `-dip1000`. Try adding one or both of those and recompiling and see what happens. Note that even if the compiler doesn't error on it, it is undefined behavior to return the stack reference so be sure to treat it right.
Sep 20 2021
On Monday, 20 September 2021 at 15:56:44 UTC, Ferhat Kurtulmuş wrote:On Monday, 20 September 2021 at 15:45:08 UTC, Adam D Ruppe wrote:I also think this is a dirty corner of the complier since it must raise an error for scoped instances of classes.On Monday, 20 September 2021 at 15:35:02 UTC, Ferhat Kurtulmuş wrote:That is what I thought too. I only tried this on the online compiler. Thank you. Have a great day or night captain.I thought it's stack-allocated and scoped.It is.But when I try to return a class instance from a function, it still works?dmd only makes that an error if you specify ` safe` and i think `-dip1000`. Try adding one or both of those and recompiling and see what happens. Note that even if the compiler doesn't error on it, it is undefined behavior to return the stack reference so be sure to treat it right.
Sep 20 2021