8c2de004   
   From: dave@boostpro.com   
      
   on Wed Dec 14 2011, kelvSYC wrote:   
      
   > Suppose I have a class hierarchy, whose root class is Foo. Is there a   
   > way to formally prescribe that subclasses of Foo has to export a   
   > type? That is:   
   >   
   > class Foo { // abstract base class   
   > // Subclasses must export a type BarType, possibly with a   
   > consistent interface - none exists for Foo itself   
   > };   
   >   
   > struct Foo1 : public Foo {   
   > typedef ... BarType;   
   > };   
   >   
   > struct Foo2 : public Foo {   
   > struct BarType { ... };   
   > };   
   >   
   > // So Foo1::BarType and FooType::BarType are valid, and Foo::BarType   
   > could be any of these two   
   >   
   > If such a thing exists, is it possible to declare an abstract method   
   > in Foo that returns BarType (where subclasses return their own   
   > BarType)?   
      
   Heh... no, there's not really a way to do what you're asking directly.   
      
   > If not, is there a good workaround?   
      
   What makes a good workaround really depends on what you're *actually*   
   trying to accomplish. It's likely that you need a different approach   
   rather than a workaround for an inability to realize this approach. Can   
   you describe your actual problem in more detail?   
      
   Thanks,   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|