www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Scope of 'alias'

reply DLearner <bmqazwsx123 gmail.com> writes:
     >>>
     void foo(pint p1) {
        alias pint=uint;
        import std.stdio;
        writeln("p1 = ", p1);
     }

     void main() {
       alias pint=uint;
       pint var1;
       var1 = 7;
       foo(var1);
     }
     <<<

Does not compile.

But the rather similar:

alias pint=uint; void foo(pint p1) { import std.stdio; writeln("p1 = ", p1); } void main() { pint var1; var1 = 7; foo(var1); } <<< Is fine. So 'alias' only valid from definition to end-of-function, rather than whole function? Best regards
May 14 2021
parent Paul Backus <snarwin gmail.com> writes:
On Friday, 14 May 2021 at 14:03:17 UTC, DLearner wrote:
 So 'alias' only valid from definition to end-of-function, 
 rather than whole function?

 Best regards
Yes. This applies to all definitions inside a function, not just aliases.
May 14 2021