digitalmars.D.learn - The compiler can not find the property function.
- choi heejo (14/14) May 30 2011 Greeting.
- David Nadlinger (18/32) May 30 2011 @property is used to mark getters/setters functions as property (i.e.
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
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