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 32,522 of 33,346   
   DeMarcus to All   
   Is this kind of static polymorphism vali   
   03 Sep 12 12:17:43   
   
   From: use_my_alias_here@blacklisted.com   
      
   Hi,   
      
   I'm experimenting with static polymorphism and came up with the   
   following. This example do run under gcc 4.7.1 but without luck I've   
   tried to find the paragraphs in the standard that allow this kind of   
   static polymorphism.   
      
      
   template   
   class Runner   
   {   
   public:   
        void run()   
        {   
           runPrivate();   
        }   
      
   private:   
        void runPrivate();   
   };   
      
      
   namespace   
   {   
        // (struct SomeRunnerLabel without declaration)   
        Runner r;   
   }   
      
   template<>   
   void Runner::runPrivate()   
   {   
        std::cout << "Static polymorphism" << std::endl;   
   }   
      
      
   int main( int argc, char* argv[] )   
   {   
        r.run();   
        return 0;   
   }   
      
      
   My questions are:   
      
   1. Am I allowed to use struct SomeRunnerLabel as I do here?   
   SomeRunnerLabel is not even a forward declaration and it just serves   
   as a label to get the polymorphism. Does anyone know where in the   
   standard I can find the paragraph that allows this kind of template   
   argument?   
      
   2. Is this kind of static polymorphism allowed at all? As we see, the   
   template parameter T is not used for anything but creating multiple   
   versions of the class, doing polymorphism on the runPrivate()   
   function.  Also for this one I would be very happy if someone could   
   direct me to the paragraph that allows this kind of polymorphism.   
      
      
   Thanks,   
   Daniel   
      
      
   --   
         [ 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