Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[]

Daniel Keep daniel.keep.lists at gmail.com
Wed Sep 5 08:11:10 PDT 2007


Tom McMurray wrote:
> I just downloaded version 2.003 or DMD and tried to compile the following :-
> 
> class stringtest
> {
>    void st1()
>    {
>        char[] s1 = "abcde";
>    }
> }
> 
> This fails with the error :-
> 
> Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[]
> 
> Is this a bug or am I doing something stupid.  This code compiled successfully on previous versions of the compiler.  Any help would be appreciated

D 2.0 is not just the version after D 1.0; it has several breaking
changes.  This is not a bug: it is a side effect of the new const system
in D 2.0.

If you downloaded it thinking it was simply a newer compiler, you might
be well advised to go back to the latest 1.x compiler.  The 1.x series
is now stable, and the 2.x series compilers could suddenly change at any
moment.

If you downloaded it because you want to play with D 2.0, then I suggest
you re-read the language documentation.  There are various bits and
pieces that have changed, and it'll save you a lot of grief if you get a
handle on it.

	-- Daniel

P.S.  To store a string literal into a char[] in D 2.0, you'll need to
use "abcde".dup in order to make a mutable copy of the string.


More information about the Digitalmars-d-learn mailing list