you could also use a simple wrapped cast
Ret castTo(Ret, T)(T t) if(is(T == class))
{
return cast(Ret) t;
}
then do
foo.stuff[0].castTo!Dong.x.writeln;
and if you want to guard the access you could try
foo.stuff[0].castTo!Dong.cc!((d){d.x = 5;});
cc is an alias for checkCall which is a t
On Thursday, 9 June 2016 at 22:19:33 UTC, Stretto wrote:
I have some class like
class bar { }
class foo : bar
{
bar[] stuff;
}
and have another class
class dong : bar
{
int x;
}
Now sometimes stuff will contain dong's, but I cannot access
its members it without a cast.
fooo.stuff[0
Ultimately what I want to do is access a member
foo.Dongs[i];
Where Dongs is essentially a "view" in to the Bars array and only
accesses types of type Dong.
It seems one can't do both an override on a name("Dongs") and an
index on the overridden name(`[i]`)?
It is not appropriate to use fo
I have some class like
class bar { }
class foo : bar
{
bar[] stuff;
}
and have another class
class dong : bar
{
int x;
}
Now sometimes stuff will contain dong's, but I cannot access its
members it without a cast.
fooo.stuff[0].x // invalid because bar doesn't contain x;
Hence,
((c