Auto keyword and when to use it

JN 666total at wp.pl
Mon Aug 20 17:55:11 UTC 2018


On Monday, 20 August 2018 at 17:52:17 UTC, QueenSvetlana wrote:
> Great!
>
> So I can't declare class level variables with auto, correct? 
> only local method variables?

You can, globals, class members:

class Foo
{
     auto bar = "hi";
}

Foo.bar will be of string type here, because "hi" is a string. 
What you can't do is:

class Foo
{
     auto bar;
}

because now the compiler doesn't know what type 'bar' is supposed 
to be.


More information about the Digitalmars-d-learn mailing list