March 14, 2005
Ben Hinkle wrote:

>>Then again, structs and even typedefs having methods do have
>>some neat uses for extending OS types or validating custom ones.
> 
> A typedef can have methods? How do you do that?

Close your eyes and wish real hard :-) (it was a suggestion)

See http://www.prowiki.org/wiki4d/wiki.cgi?Typedef-Block

> and have the conversions be implicit and the x() and y() properties inherited it
> would make for less code for me to type. Also the convertion function toPoint
> could possibly go. Given that Point is a small struct it isn't a big deal to
> explicitly type everything out and one could argue that this would be the case
> for most structs. 

Good example, that seems to be a good use of struct "inheritance".

Just syntactical sugar, but the good and sweet kind thereof...

--anders

March 14, 2005
In article <d1403i$1hgr$1@digitaldaemon.com>, Ben Hinkle says...
>
>
>>Your use of the word 'slicing' in this context threw me for a loop the first time you used it; I kept thinking 'array slicing'.
>
>oops - sorry. 'Slicing' in C++ is when you, for example, pass a derviced class to a function taking a base class and all the derived-specific data of the object is 'sliced' off. People expect that passing a derived class around would preserve the derived data. Hence why pointers to structs are so important in C++.
>

Okay, gotcha.  So the question is, is slicing back to a base struct type allowable, and if so, what is the syntax?  Should it be a part of an implicit upcast or use my slice (mystruct[BaseType]) notation (or something else)?

Both have merits.  I'm just wondering which, if either, is right for D.

- EricAnderton at yahoo
March 14, 2005
"Hiroshi Sakurai" <Hiroshi_member@pathlink.com> wrote:

> struct Rect : RECT {
> private RECT rect;
> alias rect.left   left;
> alias rect.top    top;
> alias rect.right  right;
> alias rect.bottom bottom;
>
> int width()  { return right-left; }
> int height() { return bottom-top; }
> }
>

This can not work at all, since alias is used to assign an alias of "type". Obviously, left is not a type.

Compiler will indicate the error like this : "rect.left is used as a type"

Shawn Liu


1 2 3
Next ›   Last »