argument type const char* can pass string, buf why const wchar* can not pass wstring

Jimmy Cao via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 26 22:37:01 PST 2015


On Sunday, 27 December 2015 at 03:34:18 UTC, riki wrote:
> void ccf(const char* str){}
> void cwf(const wchar* str){}
>
> void main()
> {
>     ccf("aaa");    //ok
>     cwf("xxx"w); // error and why ?
> }

You need to remove the w suffix.  Otherwise it is forcibly typed 
as a dynamic array and is no longer implicitly convertible.

void cwf(const wchar* str){}
void main()
{
     ccf("aaa");    //ok
     cwf("xxx"); // a string literal
}


More information about the Digitalmars-d-learn mailing list