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 fun(const ref Foo foo = Foo(1));
---
This yields an error: "Foo(1) is not an lvalue and cannot be
modified". I suppose this makes sense with how D references
work, but I have no control over how the C++ function is
declared. What can I do with this?
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);
---