Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / Templates and Inheritance question Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Chris

February 23, 2005, 09:47 AM

Hi everybody,

I seem to require a bit of help with templates and inheritance, I can't get this right.

I want to have a bunch of classes that derive from a base class given as a template parameter:

  1.  
  2. template< class base >
  3. class foo : public base
  4. {
  5. };
  6.  


This way classes can get stacked onto each other
  1.  
  2. typedef foo1< foo2< foo3< bar > > >  some_type_t;
  3.  


That works so far. Now I want foo2, foo3 and bar to be aware of the topmost type resulting from the stacking of classes (some_type_t, or it's typedefed equivalent), that is, each of them should typedef a member type equivalent to some_type_t. How would I do that ?

The approach
  1.  
  2. template< class topmost, class base >
  3. class foo2 : public base
  4. {
  5. public:
  6.   typedef typename topmost topmost_t;
  7. };
  8.  

obviously doesn't work, because I would have to specify some_type_t as a template parameter _before_ it's readily defined.
  1.  
  2. typedef foo1< ??, foo2< ??, foo3< ??, bar < ?? > > > > some_type_t,
  3.  

?? being some_type_t itself. This cannot work.

Any ideas anybody ?

Thank you,
Christian

 
Moe

February 23, 2005, 10:02 AM

Sorry I have not really a solution. But I am wondering, could you point out one situation where such an approach would be useful?

 
This thread contains 2 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.