www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - alias this ...

reply BLS <windevguy hotmail.de> writes:
// ..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
parent reply BLS <windevguy hotmail.de> writes:
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
parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
BLS wrote:
 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

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.
Sep 06 2010