struct opCall makes a nan

dominik asd at asd.com
Sun Mar 23 20:13:12 PDT 2008


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:fs7209$2jld$1 at digitalmars.com...
> dominik wrote:
>> it works now, thanks!
>
> Great.  Did you need to add an explicit call to it?

yes I did, it works however :)

> Because you don't have any instance at the time you're calling it. Maybe 
> you're thinking of it like the equivalent of a constructor.  It's not. 
> It's just a hack that's been somewhat canonicalized by the language.

thats what confused me I guess. I've seen that idiom over and over again in 
D Language without fully understanding why it is so. I guess I started to 
look at it as a class with constructor - while it's obviously not. I think 
I'll stick to struct for vectors, but I still need to figure out why/when 
structs and why/when classes in D.

> [*] Except that D will automatically call a single-argument static opCall 
> if an initializer matches the opCall's argument.  So if for some reason 
> you had
>    static plane opCall(string x) { ... }
> and did
>    plane foo = "hi there";
> that would call your static opCall(string) method.  Otherwise static 
> opCall is just an ordinary static method.

I like verbose code though, so I'll stick to plane foo = plane("hi there") 
as I don't like to write lots of comments in code :) 




More information about the Digitalmars-d-learn mailing list