alias & local function

Alain De Vos devosalain at ymail.com
Mon May 10 01:25:10 UTC 2021


The following program runs correctly
```
import std.stdio;
int afunction(int x){return x;};
void main()
{
		alias myint = int;
		myint i=5;
		alias tfunction = int function(int);
		tfunction f = & afunction;
		writeln(f(1));
}
```

This does not:
```
import std.stdio;
void main()
{
		int afunction(int x){return x;};
		alias myint = int;
		myint i=5;
		alias tfunction = int function(int);
		tfunction f = & afunction;
		writeln(f(1));
}
```
It gives compile error :
Error: cannot implicitly convert expression &afunction of type 
int delegate(int x) pure nothrow @nogc @safe to int function(int)




More information about the Digitalmars-d-learn mailing list