What is the correct use of auto?

Bill Baxter dnewsgroup at billbaxter.com
Fri Apr 11 14:04:42 PDT 2008


Unknown W. Brackets wrote:
> It might help you to understand auto if you try this:
> 
> auto i;
> 
> It will not compile.  In this case, i has no type.  Remember that i is 
> not some boxed variable or something... it's simply type inference.
> 
> -[Unknown]

And also you should be aware that it's the *lack* of a specific type 
that triggers the inference, not the *presence* of auto.  These do type 
inference too:

// D1
static x = 2.3;
static assert(is(typeof(x)==double));

const y = "hello";
static assert(is(typeof(y)==char[]));

--bb



More information about the Digitalmars-d mailing list