www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static array in templated struct/class

reply "ddos" <oggs gmx.at> writes:
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
Aug 05 2014
parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
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;
Aug 05 2014
next sibling parent Daniel Gibson <metalcaedes gmail.com> writes:
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?
Aug 05 2014
prev sibling parent reply "ddos" <oggs gmx.at> writes:
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
Aug 05 2014
parent reply Philippe Sigaud via Digitalmars-d-learn writes:
 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);}
Aug 05 2014
parent "ddos" <oggs gmx.at> writes:
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);}
Aug 05 2014