How to pass a class by (const) reference to C++

Jan Jan at Krassnigg.de
Thu Dec 16 08:30:14 UTC 2021


On Wednesday, 15 December 2021 at 22:50:38 UTC, Tim wrote:
> On Wednesday, 15 December 2021 at 22:46:01 UTC, Jan wrote:
>> Btw. should I report this issue somewhere? Is far as I see 
>> this isn't logged yet:
>> <https://issues.dlang.org/buglist.cgi?quicksearch=c%2B%2B%20extern%20static>
>
> Yes, it should be reported.

Ok, next problem. Maybe you know the necessary syntax for this 
one too.


C++
```cpp
class Test
{
public:
   __declspec(dllexport) static const int const_vars[2];
   __declspec(dllexport) static int nonconst_vars[2];
};

const int Test::const_vars[2] = {11, 23};
int Test::nonconst_vars[2] = {12, 24};
```

D
```cpp
extern(C++, class) struct Test
{
     extern export static __gshared const(int)[2] const_vars;
     extern export static __gshared int[2] nonconst_vars;
}
```

I get the nonconst_vars to link correctly, but for the const_vars 
the mangled name contains one less const than what MSVC 
generates, so I assume I have to wrap this somehow differently. I 
tried "const(int[2])" but that didn't make a difference.

D wants to link against:
`?const_vars at Test@@2PAHB`

which is:
`public: static int * const Test::const_vars" ()`

MSVC exports:
`?const_vars at Test@@2QBHB`

which is:
`public: static int const * const Test::const_vars`


Any idea?


More information about the Digitalmars-d-learn mailing list