Nested function declarations

Akakima akakima33 at gmail.com
Thu Jan 27 18:35:00 PST 2011


"bearophile" <bearophileHUGS at lycos.com> a écrit dans le message de news: 
iht0ha$2avd$1 at digitalmars.com...
> This D2 code:
>
> import std.math: sqrt;
> void main() {
>    double sqrt();
>    double result = sqrt(9.0);
> }
>
> Generates the errors:
> test.d(4): Error: function test.main.sqrt () is not callable using 
> argument types (double)
> test.d(4): Error: expected 0 arguments, not 1 for non-variadic function 
> type double()
>

--- This one compiles, but does not link:

import std.math: sqrt;
void main()
{
  double sqrt(double x);
  double result = sqrt(9.0);
}


--- And this one compiles and links ok.

import std.math: sqrt;
void main()
{
  double sqrt(double x)  {    return 1.0;  }
  double result = sqrt(9.0);
}

So, with the appropriate prototype it compiles, but
there is a conflict with the sqrt() already defined in Phobos.





More information about the Digitalmars-d-learn mailing list