The compiler can not find the property function.
Jonathan M Davis
jmdavisProg at gmx.com
Mon May 30 13:03:29 PDT 2011
On 2011-05-30 08:54, choi heejo wrote:
> Greeting.
>
> I tried to compile this code with DMD 2.053:
>
> @property bool isZero(float value)
> {
> return value < float.epsilon;
> }
>
> void main()
> {
> 0.1f.isZero;
> readln();
> }
>
> But the compiler said,
>
> no property 'isZero' for type 'float'.
>
> I cannot understand this error.
Property functions and uniform function call syntax are two separate things.
When a function is a property function, then it is called without parens as it
were a member variable. It only works with types which can already be called
as if they had member functions - which are structs, classes, and arrays.
Arrays are currently the only type with no built-in member functions which can
call other functions as if they were member functions. For that to work with
any type would be called universal function call syntax, and that hasn't been
implemented. And it may never be implemented. Using the member function call
syntax like that only works with structs, classes, and arrays.
So, your example doesn't work because it's illegal to call a function on a
float as if it that function were its member function. So, if @property were
enforced such that you had to call it as if it were a member variable (the
enforcement hasn't been added to the compiler yet), it would actually become
illegal to call isZero.
The "no property 'X' for type 'Y'" error message is what the compiler always
gives when it can't find a property or function that it's looking for. float
_does_ have some built-in properties (such as min, max, and init), but isZero
isn't one of them, and without UFCS, you can't add any.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list