08.10.2010 16:19, %u wrote:
Hi,
I'm learning D right now and got a question about property.
I tried to add a property for built-in type like the following
@property bool equalZero(double a) { return a == 0.0; }
void main()
{
...
double x = 4.4;
bool isXZero = x.equalZero;
...
}
but got an error message
main.d(75): Error: no property 'equalZero' for type 'double'
I tried similar thing with int[] and it works.
Is that I did something wrong or property does not support built-in type like
double, int, real, ...?
Appreciate for your time and answer.
What you're trying to do is utilize uniform function call syntax (foo(T)
=== T.foo()), but that is currently supported *only* for arrays. AFAIK
it's going to be implemented at some point, but right now you will have
to use equalZero(a) instead of a.equalZero.