home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,093 of 33,346   
   =?ISO-8859-1?Q?=D6=F6_Tiib?= to Norman J. Goldstein   
   Re: template virtual methods   
   26 May 13 22:15:15   
   
   From: ootiib@hot.ee   
      
   On Sunday, 26 May 2013 23:20:02 UTC+3, Norman J. Goldstein  wrote:   
   > class Car   
   > {   
   >  // Does some kind of measurement, depending on the car.   
   >  template< class DERIVED>   
   >  void measure( Vector& vec );   
   > };   
      
   Here I would use some (possibly polymorphic) wrapper around that   
   'Vector& vec' and pass that instead or use some technique of   
   double dispatch. Note that the 'vec' feels to be at wrong level of   
   abstraction: "please measure me a car using that vec" begs for a   
   question: "what the heck is that vec?".   
      
   > class Fiat : public Car   
   > {   
   >  // Here is the Fiat-specific implementation   
   >  template< class DERIVED>   
   >  void measure( Vector& vec );   
   > };   
   >   
   > The "measure" method cannot be virtual, since it is templated.   
      
   Yes, but what remains dim is why it is templated. It can't be that any   
   'Vector' is fine for measuring any car?   
      
      
   --   
         [ 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)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca