Get specific functions of unknown type at runtime?
    F i L 
    witte2008 at gmail.com
       
    Sun Dec 16 23:54:07 PST 2012
    
    
  
@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.
@Jacob Carlborg
Thanks for the link.
    
    
More information about the Digitalmars-d-learn
mailing list