parse int error

Jonathan M Davis jmdavisProg at gmx.com
Tue Oct 29 18:42:19 PDT 2013


On Wednesday, October 30, 2013 02:02:40 Peter Eisenhower wrote:
> I am confused as to why I cannot pass the return of the tag
> attribute directly into the parse int.
> 
> // This works
> string s = xml.tag.attr["key"];
> int key = parse!int(s);
> 
> // Compile error on these
> int key = parse!int(xml.tag.attr["key"]);
> int key = parse!int(cast(string) cml.tag.attr["key"]);

parse takes the string by ref and removes what it's parsing from the string, 
so it can't be a temporary. It has to be an lvalue. Also, casting results in 
an rvalue. To use parse, you should generally be using a local variable for 
the string.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list