www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - The compiler can not find the property function.

reply choi heejo <azurenote.enseed gmail.com> writes:
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.
May 30 2011
parent David Nadlinger <see klickverbot.at> writes:
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
May 30 2011