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 31,786 of 33,346    |
|    Johannes Schaub to All    |
|    Re: Why is static member initialization     |
|    11 Jan 12 14:18:05    |
   
   From: schaub.johannes@googlemail.com   
      
   Am 06.01.2012 06:29, schrieb DeMarcus:   
   >   
   > Ok, thanks!   
   > The only workaround I've found so far is the following in the   
   > constructor of PrintingYou:   
   >   
   > struct PrintMe   
   > {   
   > PrintMe() { std::cout << "PrintMe" << std::endl; }   
   > };   
   >   
   > template   
   > struct PrintingYou   
   > {   
   > PrintingYou()   
   > {   
   > pm; // Refer to pm and hope this constructor is used.   
   > }   
   >   
   > static PrintMe pm;   
   > };   
   > template   
   > PrintMe PrintingYou::pm;   
   >   
   >   
   > I don't like this solution, first and foremost because it's unintuitive   
   > programming.   
      
   You can put a typedef there. Declarations are instantiated immediately,   
   so the following will instantiate the static data member properly as   
   soon as PrintingYou is instantiated.   
      
   template   
   struct PrintingYou {   
    static PrintMe pm;   
      
    template struct Value;   
    typedef Value ref_type;   
   };   
      
      
   --   
    [ 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