Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 05, 2007 Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] | ||||
---|---|---|---|---|
| ||||
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 |
September 05, 2007 Re: Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom McMurray | Reply to Tom,
> 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
>
char[] s1 = "abcde"[];
this should work.
(No comment on the issue)
|
September 05, 2007 Re: Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom McMurray |
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.
|
September 05, 2007 Re: Error: cannot implicitly convert expression ("abcde") of type invariant char[5u] to char[] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tom McMurray | 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
Try 'string' instead of 'char[]'. String is an alias for 'const(char)[]', which an 'invariant char[5u]' can be implicitly converted to.
And I wouldn't write too much code for D 2.0 just yet, things might change. There was even talk of changing the const stuff.
|
Copyright © 1999-2021 by the D Language Foundation