struct and class member alias

Stuart Murray stuart.w.murray at fakey.nospambots.gmail.com
Tue Jun 5 09:29:01 PDT 2007


In the following, the aliases have no apparent effect (although they do compile). Is there a way to achieve a similar effect? I just want to be able to access 
boxInstance.pos.x
using
boxInstance.x

I got the alias idea from the function page in the documentation:
http://digitalmars.com/d/function.html
under Function Inheritance and Overloading
obviously it doesn't describe the same thing, but I figured I'd give it a shot.
Given that it doesn't seem to work I was thinking that it might be a handy feature to have in the language?

I tried this as a struct(suitably modified) also.

public class Coord
{
	int x, y;
	
	this
	   (in int x, in int y)
	{
		this.x = x;
		this.y = y;
	}
}

public class Box
{
	Coord pos, size;
	
	alias pos.x  x;
	alias pos.y  y;
	alias size.x w;
	alias size.y h;
	
	this
	   (in int x, in int y, 
		in int w, in int h)
	{
		pos  = new Coord(x, y);
		size = new Coord(w, h);
	}
}


More information about the Digitalmars-d-learn mailing list