Is there a keyword to access the base class
    Steven Schveighoffer 
    schveiguy at yahoo.com
       
    Tue Jun 18 15:54:32 PDT 2013
    
    
  
On Tue, 18 Jun 2013 18:10:49 -0400, Stephen Jones <siwenjo at gmail.com>  
wrote:
> I know I can cast, but how do I know what base class each b in the  
> foreach loop is?
Just an FYI, you are using the wrong terminology.  In this case, Bar is  
the base class, and Foo and Foos are the *derived* classes.
Other than that, I think Ali gave you the best solution.
If you wanted to do something that *wasn't* common between two derived  
classes (i.e. some function/member that was only on one specific derived  
class), you can use a nice technique called auto-casting:
if(auto der = cast(Foo)b)
{
    // use Foo specific functionality on der
}
else if (auto der = cast(Foos)b)
{
    // use Foos specific functionality on der
}
Hm... would be a nice idiom to implement generically in D.  Like a type  
switch.
-Steve
    
    
More information about the Digitalmars-d-learn
mailing list