digitalmars.D.learn - alias this ...
- BLS (30/30) Sep 06 2010 // ..snip
- BLS (4/6) Sep 06 2010 should be
- Stanislav Blinov (9/18) Sep 06 2010 Struct is value type, not reference type like class. You don't need
// ..snip
point3D p; // Da
p.x = 10;
p.y = 20;
p.z = 100;
point3D = = new point3D(10,20,30) // Njet
//etc
}
struct point {
int x;
int y;
}
struct point3D {
point p;
alias p this;
int z;
// NOPE :(
/*static point3D opcall(int _x, int _y, int _z) {
// ..snip
}*/
// NOPE :(
/*
this(int _x, int _y, int _z) {
// .. snip
}
*/
}
would be nice to use alias this as struct inheritance substitute,
especially in conjunction with Implements!()
But maybe I don't get the "alias this" thingy. So what's my mistake > TIA
Sep 06 2010
On 06/09/2010 22:36, BLS wrote:
point3D = = new point3D(10,20,30) // Njet
//etc
should be
point3D p3 = new point3D(10,20,30) // Njet
sorry
Sep 06 2010
BLS wrote:On 06/09/2010 22:36, BLS wrote:Struct is value type, not reference type like class. You don't need 'new' to create it, just uncomment your constructor ('this') and remove 'new': point3D p3 = point3D(10,20,30); If you really need to allocate a point on the heap, then you'd have to use pointers: point3D* p3 = new point3D(10,20,30); Though you probably wouldn't need that much.point3D = = new point3D(10,20,30) // Njet //etcshould be point3D p3 = new point3D(10,20,30) // Njet sorry
Sep 06 2010








Stanislav Blinov <stanislav.blinov gmail.com>