Thread overview
alias this ...
Sep 06, 2010
BLS
Sep 06, 2010
BLS
Sep 06, 2010
Stanislav Blinov
September 06, 2010
// ..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
September 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
September 06, 2010
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.