Type of string literal concatenated with non-immutable char array
Per Nordlöw
per.nordlow at gmail.com
Sun Jan 31 21:48:09 UTC 2021
Given
char x[];
why is
typeof("a" ~ x)
`char[]` when
typeof("a" ~ x.idup)
is
`string`?
My case is
class NameLookupException : Exception
{
this(string name) {
super("Name " ~ name ~ " could not be found");
}
this(scope const(char)[] name) {
super("Name " ~ name.idup ~ " could not be found");
}
}
where I instead would like to only need
class NameLookupException : Exception
{
this(scope const(char)[] name) {
super("Name " ~ name ~ " could not be found");
}
}
Why isn't
"Name " ~ name ~ " could not be found"
implicitly convertible to `string`?
Would
class NameLookupException : Exception
{
this(scope const(char)[] name) @trusted {
super("Name " ~ cast(string)name ~ " could not be found");
}
}
be ok?
More information about the Digitalmars-d-learn
mailing list