Anonymous structs
Jacob Carlborg
doob at me.com
Mon Feb 11 23:46:31 PST 2013
On 2013-02-11 23:20, Era Scarecrow wrote:
> What if there's another anonymous struct that has a little more?
>
> { int x, int y } point = { y: 4, x: 5 };
> { int x, int y, int color } color_point
> = { y: 4, x: 5, color: 0x000000 };
> //which anonymous struct does it go with?
> //Or can auto only work with named/returned structs?
> auto point2 = { x: 1, y: 2 };
>
> point = point2; //error, point2 type void _error
"point2" is completely independent of the other declarations. But you
can think of it having the same type as "point". It can also be
implicitly converted to "color_point". It's not the actual type that's
interesting, it's the members. The compiler checks the members to see if
two values are of the same types.
> We can instantiate structs with fewer arguments than elements they
> hold. It would either have to go the safe route, or try it's best to
> either be 'safe' or 'whatever seems to work' until you change something
> and break it utterly with no description of 'what' it is.
It's not the actual type that's interesting, as long as the members
match they're considered to be the same type.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list