The compiler can not find the property function.

David Nadlinger see at klickverbot.at
Mon May 30 09:01:56 PDT 2011


On 5/30/11 5:54 PM, 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 is used to mark getters/setters functions as property (i.e. 
callable without parenthesis) – what you are trying to do would require 
uniform function calling syntax (UFCS), which is only implemented for 
arrays so far (its future is unclear right now).

Just to make it clear, the canonical example of property functions would be:
---
struct Foo {
   int bar() @property { return …; }
   void bar(int value) @property { … }
}

void main() {
   Foo f;
   writeln(f.bar); // No parentheses required to call bar().
   f.bar = 5; // Can use assignment to invoke bar(int).
}
---

David


More information about the Digitalmars-d-learn mailing list