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 31,813 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: Why is static member initialization    
   17 Jan 12 14:19:28   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 17.01.2012 21:08, schrieb Frank Birbacher:   
   [..]   
   > I like the typedef approach. I didn't know it needs to instantiate the   
   > complete template. My approach is a little more overhead, but maybe it   
   > tricks the compiler into instantiation. I suggest to use an empty class   
   > template ForcePrintMe whose type depends on&PrintingYou::pm like this   
   > (tested on gcc4.6, not tested on VS2010, maybe one of you can do so and   
   > post the result):   
   >   
   > #include   
   > #include   
   >   
   > struct PrintMe   
   > {   
   > 	PrintMe() { std::cout<<  "PrintMe"<<  std::endl; }   
   > };   
   >   
   > template   
   > struct ForcePrintMe {};   
   >   
   > template   
   > struct PrintingYou   
   > {   
   > 	static PrintMe pm;   
   > 	static ForcePrintMe<&PrintingYou::pm>  f;   
   > };   
   > template   
   > PrintMe PrintingYou::pm;   
   > template   
   > ForcePrintMe<&PrintingYou::pm>  PrintingYou::f;   
   >   
   > int main()   
   > {   
   > 	PrintingYou  y;   
   > 	(void)y;   
   > }   
      
   Unfortunately, VS2010 does not construct the PrintMe object in this   
   example either. Nor does making y a global object of static storage   
   duration cause a change of this situation :-(   
      
   Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ 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