April 15, 2004 Struct constructors | ||||
---|---|---|---|---|
| ||||
Just started looking at D (from a game programming perspective) and it seems superb in almost every way, except it doesn't appear that structs can have constructors. Is this correct? If so, how am I to implement a usable Vector4 type (i.e. an array of 4 floats)? And please don't tell me to make it a class - the overhead is not acceptable - this has to be a value type. Here's hoping I'm missing something. Si |
April 15, 2004 Re: Struct constructors | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simon Hobbs | Simon Hobbs wrote:
> Just started looking at D (from a game programming perspective) and it seems
> superb in almost every way, except it doesn't appear that structs can have
> constructors. Is this correct?
>
> If so, how am I to implement a usable Vector4 type (i.e. an array of 4 floats)?
> And please don't tell me to make it a class - the overhead is not acceptable -
> this has to be a value type.
>
> Here's hoping I'm missing something.
You can override operator() and make it static like so:
struct Vec4
{
float w,x,y,z;
static Vec4 opCall(float W, float X, float Y, float Z) {
...
}
}
Vec4 blah = Vec4(0,0,0,1);
-- andy
|
Copyright © 1999-2021 by the D Language Foundation