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:
--20cf305b123413333604a4804feb
Content-Type: text/plain; charset=UTF-8

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.

--20cf305b123413333604a4804feb
Content-Type: text/html; charset=UTF-8

<div>Greeting.</div><div><br></div><div>I tried to compile this code with DMD
2.053:</div><div><br></div><div> property bool isZero(float
value)</div><div><div>{</div><div><span
style="white-space:pre-wrap">	</span>return value &lt; float.epsilon;</div>

<div>}</div><div><br></div><div>void main()</div><div>{</div><div><span
style="white-space:pre-wrap">	</span>0.1f.isZero;</div><div><span
style="white-space:pre-wrap">	</span></div><div>
<span style="white-space:pre-wrap">	</span>readln();</div><div>}</div><di
><br></div><div>But the compiler said,</div><div><br></div><div>no property
&#39;isZero&#39; for type &#39;float&#39;.</div><div><br></div><div>I cannot
understand this error.</div>
<div>
<br>
</div></div>

--20cf305b123413333604a4804feb--
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