Get specific functions of unknown type at runtime?
Jacob Carlborg
doob at me.com
Mon Dec 17 01:03:06 PST 2012
On 2012-12-17 08:54, F i L wrote:
> @Adam D. Ruppe
>
> Damn, I was afraid you where going to say to do something like that. It
> doesn't really work for what I'm thinking about, but thanks for
> confirming that my original code can't work.
>
> I have an alternative in mind, but first, is there a possible way for a
> Super class to ask about a derivative's members during constructions?
> (I'm guessing not). Something like:
>
> import std.stdio, std.traits;
>
> class A
> {
> this() {
> alias typeof(this) type;
> static if (hasMember!(type, "foo")) {
> auto top = cast(type) this;
> top.foo();
> }
> }
> }
>
> class B : A
> {
> void foo() { writeln("foobar"); }
> }
>
> void main() {
> auto b = new B(); // prints: 'foobar'
> }
>
> I assume there's no way (I can't get it to work), but I've heard odd
> things about 'typeof(this)' before, I just can't remember exactly what,
> so I figure it's worth asking about.
>
> If not, I have an alternative way to accomplish what I want. It's just
> not as ideal. I really wish D has partial classes, that would be awesome.
Don't know if this is what you need, but you could talk a look at:
http://flectioned.kuehne.cn/
It's basically runtime reflection implemented by inspecting the symbol
table in the currently running executable. Note that this is old D1 code.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list