Passing string from D to c++

deadalnix deadalnix at gmail.com
Wed Jul 31 00:17:13 PDT 2013


On Wednesday, 31 July 2013 at 06:07:07 UTC, Jesse Phillips wrote:
> On Wednesday, 31 July 2013 at 05:44:38 UTC, deadalnix wrote:
>> On Tuesday, 30 July 2013 at 20:57:55 UTC, Jesse Phillips wrote:
>>> On Tuesday, 30 July 2013 at 20:09:01 UTC, Milvakili wrote:
>>>
>>>> So I need to pass them as char*, I can not pass them as 
>>>> string?
>>>
>>> C++ doesn't have an immutable(char)[], it has char* and its 
>>> own string class. To communicate with it one must choose a 
>>> type both languages can understand, char* is that. D may be 
>>> able to get away with providing a C++ string, but I'm not 
>>> familiar with the integration layer.
>>
>> const char*, char const* are equivalent to const(char)* in D.
>
> I was referring to string types:
> http://www.cplusplus.com/reference/string/string/
>
> If his C++ functions takes a const char* he should be passing it
> a const/immutable(char)* as you say, not an immutable(char)[]

In C++, std::string own its own copy of the string. So it is safe 
to pass a D const char* to the constructor.


More information about the Digitalmars-d mailing list