Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread Mathias LANG via Digitalmars-d-learn
On Monday, 14 September 2020 at 18:58:44 UTC, 60rntogo wrote: On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote: AFAIK the only way to have default ref arguments is to use a global variable: --- extern(C++) struct Foo { int x; } immutable foo1 = Foo(1); extern(C++) void fun(const ref F

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
On Monday, 14 September 2020 at 17:11:59 UTC, k2aj wrote: AFAIK the only way to have default ref arguments is to use a global variable: --- extern(C++) struct Foo { int x; } immutable foo1 = Foo(1); extern(C++) void fun(const ref Foo foo = foo1); --- Thanks. This appears to work, but feels l

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread k2aj via Digitalmars-d-learn
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote: I'm trying to use a C++ library that has a function declared like this: --- struct Foo { int x; }; void fun(const Foo& foo = Foo(1)); --- I have translated this to a D declaration: --- struct Foo { int x; } extern(C++) void f

Re: default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
On Monday, 14 September 2020 at 12:44:34 UTC, 60rntogo wrote: --- struct Foo { int x; } extern(C++) void fun(const ref Foo foo = Foo(1)); --- I suppose this should have been: --- extern(C++): struct Foo { int x; } void fun(const ref Foo foo = Foo(1)); --- Not that it changes the questi

default arguments for const ref parameters in extern C++ functions

2020-09-14 Thread 60rntogo via Digitalmars-d-learn
I'm trying to use a C++ library that has a function declared like this: --- struct Foo { int x; }; void fun(const Foo& foo = Foo(1)); --- I have translated this to a D declaration: --- struct Foo { int x; } extern(C++) void fun(const ref Foo foo = Foo(1)); --- This yields an error: "Foo