new to D2.0 , invariant problem
Steven Schveighoffer
schveiguy at yahoo.com
Thu Nov 20 04:43:18 PST 2008
"MikeRJ" wrote
> For some reason i think DM 1.0 is slowly dieing as i see tons of new
> features in D 2.0's phobos not implemented in D 1.0 so im trying to
> migrate to D2.0
>
> my 1st problem is when i compile code:
>
> bool open(char[] fn, char[] mode="rb")
> {
> filename=fn.dup;
> file = fopen(toStringz(filename), toStringz(mode));
> if (!file) return false;
> return true;
> }
>
> i receive error:
>
>>> cannot implicitly convert expression ("rb") of type invariant(char[2u])
>>> to char[]|
> can anyone help here. thanks in advance.
The correct const-contract usage is:
bool open(const(char)[] fn, const(char)[] mode = "rb")
That is, you are saying open does not modify fn or mode. It simply uses
them as input parameters.
The D1/D2 compatible version that Kagamin posted is also legal (and pretty
much the same thing).
-Steve
More information about the Digitalmars-d-learn
mailing list