check type

spir denis.spir at gmail.com
Sat Nov 6 10:21:37 PDT 2010


Hello,


What is the common idiom to check whether the type of a given element is what I expect?
Seems that
	typeof(e) == Type
is refused by the compiler, for any reason? I get
	DeeMatch.d(237): Error: type string is not an expression
I'm using
	typeof(e).stringof == "TypeName" 
Is there a better solution?

Also, how to override a class's field so that it is accessed according actual/runtime type? (Like method dispatch.)
	void method (SuperType x) {...access x.f...}
If I don't define f in SuperType, then I get a compiler error. If I do, then SuperType.f is accessed, not the field on actual class of x.


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list