Need help with accessing outer object

Cherry via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 29 19:43:16 PDT 2016


Greetings All

Can you help me with this code? I could not find any traits or 
other way to get me outer object of a given inner object. As for 
the context, I am fiddling with D trying to write a (domain 
specific) generic baseclass library. InnerBase is part of the 
library I write and the end user would be coding Outer and Inner 
classes. I do not want to force him to write getOuter kind of 
function. I would prefer not to ask him to add a mixin as well.

Is that possible, or is forcing the user to add a mixin the only 
way out?

Regards
- Cherry

////////////////////////////////////////////////////

class InnerBase{}
class Outer {
   class Inner: InnerBase {}
}
void main() {
   Outer outer = new Outer;
   auto inner = outer.new Outer.Inner();
   foo(inner);
}
void foo(T)(T t) {
   // somehow access inner.outer -- inner -> this.outer
   // Can not change Inner class to introduce getOuter 
functionality
   // I have access to InnerBase though and can add code there
}



More information about the Digitalmars-d mailing list