Thread overview
static array in templated struct/class
Aug 05, 2014
ddos
Aug 05, 2014
Marc Schütz
Aug 05, 2014
Daniel Gibson
Aug 05, 2014
ddos
Aug 05, 2014
Philippe Sigaud
Aug 05, 2014
ddos
August 05, 2014
alias Vec4f = TVector!(float,4);
alias Vec3f = TVector!(float,3);

class TVector(T,int n)
{
	T[n] val;
...

TVector as class does work as expected, as a struct i get the following errors, but why?

struct Vector.TVector!(float, 4).TVector no size yet for forward reference
struct Vector.TVector!(float, 3).TVector no size yet for forward reference
August 05, 2014
On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:
> alias Vec4f = TVector!(float,4);
> alias Vec3f = TVector!(float,3);
>
> class TVector(T,int n)
> {
> 	T[n] val;
> ...
>
> TVector as class does work as expected, as a struct i get the following errors, but why?
>
> struct Vector.TVector!(float, 4).TVector no size yet for forward reference
> struct Vector.TVector!(float, 3).TVector no size yet for forward reference

Can you show the complete code? I cannot reproduce this with either latest DMD git, DMD 2.065, or LDC 0.13.0:

    alias Vec4f = TVector!(float,4);
    alias Vec3f = TVector!(float,3);

    struct TVector(T,int n)
    {
        T[n] val;
    }

    Vec3f a;
    Vec4f b;
August 05, 2014
Am 05.08.2014 21:13, schrieb "Marc Schütz" <schuetzm@gmx.net>":
> On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:
>> alias Vec4f = TVector!(float,4);
>> alias Vec3f = TVector!(float,3);
>>
>> class TVector(T,int n)
>> {
>>     T[n] val;
>> ...
>>
>> TVector as class does work as expected, as a struct i get the
>> following errors, but why?
>>
>> struct Vector.TVector!(float, 4).TVector no size yet for forward
>> reference
>> struct Vector.TVector!(float, 3).TVector no size yet for forward
>> reference
>
> Can you show the complete code? I cannot reproduce this with either
> latest DMD git, DMD 2.065, or LDC 0.13.0:
>
>      alias Vec4f = TVector!(float,4);
>      alias Vec3f = TVector!(float,3);
>
>      struct TVector(T,int n)
>      {
>          T[n] val;
>      }
>
>      Vec3f a;
>      Vec4f b;

struct vs class?
August 05, 2014
On Tuesday, 5 August 2014 at 19:13:31 UTC, Marc Schütz wrote:
> On Tuesday, 5 August 2014 at 18:36:35 UTC, ddos wrote:
>> alias Vec4f = TVector!(float,4);
>> alias Vec3f = TVector!(float,3);
>>
>> class TVector(T,int n)
>> {
>> 	T[n] val;
>> ...
>>
>> TVector as class does work as expected, as a struct i get the following errors, but why?
>>
>> struct Vector.TVector!(float, 4).TVector no size yet for forward reference
>> struct Vector.TVector!(float, 3).TVector no size yet for forward reference
>
> Can you show the complete code? I cannot reproduce this with either latest DMD git, DMD 2.065, or LDC 0.13.0:
>
>     alias Vec4f = TVector!(float,4);
>     alias Vec3f = TVector!(float,3);
>
>     struct TVector(T,int n)
>     {
>         T[n] val;
>     }
>
>     Vec3f a;
>     Vec4f b;

http://pastebin.com/34sbffSa
thx for your help :) !
i use DMD 2.065 btw
August 05, 2014
> http://pastebin.com/34sbffSa

Your problem comes from lengthSquared:

public auto lengthSquared = function () => val.reduce!((a,b) => a + b*b);

That's an unusual way to define a method. Any reason why you are using a pointer to a function as a member? Do you need to be able to redefine it at runtime?

I guess that in this case, the compiler cannot determine its return
type and/or its size?
I'd use:

public auto lengthSquared () { return val.reduce!((a,b) => a + b*b);}
August 05, 2014
i wasn't intentionally creating a functionpointer, i just liked the syntax x3 ... but i guess i should read into it now :)
thx for you help !

On Tuesday, 5 August 2014 at 19:51:33 UTC, Philippe Sigaud via Digitalmars-d-learn wrote:
>> http://pastebin.com/34sbffSa
>
> Your problem comes from lengthSquared:
>
> public auto lengthSquared = function () => val.reduce!((a,b) => a + b*b);
>
> That's an unusual way to define a method. Any reason why you are using
> a pointer to a function as a member? Do you need to be able to
> redefine it at runtime?
>
> I guess that in this case, the compiler cannot determine its return
> type and/or its size?
> I'd use:
>
> public auto lengthSquared () { return val.reduce!((a,b) => a + b*b);}