home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12544 < prev    next >
Encoding:
Text File  |  1992-08-19  |  2.0 KB  |  55 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!caen!sdd.hp.com!apollo.hp.com!netnews
  3. From: vinoski@apollo.hp.com (Stephen Vinoski)
  4. Subject: Re: template static data members
  5. Sender: usenet@apollo.hp.com (Usenet News)
  6. Message-ID: <Bt8K2o.Azy@apollo.hp.com>
  7. Date: Wed, 19 Aug 1992 14:54:23 GMT
  8. References: <Bt5FDH.DFK@apollo.hp.com> <4086@seti.UUCP>
  9. Nntp-Posting-Host: zep_e.ch.apollo.hp.com
  10. Organization: Hewlett-Packard Corporation, Chelmsford, MA
  11. Lines: 42
  12.  
  13. In article <4086@seti.UUCP> Daniel R. Edelson <edelson@sor.inria.fr> writes:
  14. >In article <Bt5FDH.DFK@apollo.hp.com>, vinoski@apollo.hp.com (Stephen Vinoski) writes:
  15. >|> 
  16. >|>     template<class T> Simple LessSimple<T>::s;
  17. >|> 
  18. ><problem and explanation omitted>
  19. >|> 
  20. >|> Unfortunately, in the example case
  21. >|> above, ``s'' cannot be explicitly initialized, and the problem cannot
  22. >|> be solved without changing the declaration of Simple so such
  23. >|> initialization is allowed (if possible).
  24. >|> 
  25. >|> -steve
  26. >
  27. >Can't it be initialized with a temporary which the compiler
  28. >may or may not optimize away?
  29. >
  30. >    template<class T> Simple LessSimple<T>::s = Simple();
  31. >
  32. >(Not that this makes the bug much less annoying.)
  33.  
  34. Yes, this works.  I had tried this a couple months ago when I first
  35. ran into this problem, but I must have done something wrong because it
  36. didn't work. :-(
  37.  
  38. Regardless of my error, the real problem underlying all of this is
  39. that the compiler cannot tell a legal program containing an
  40. uninitialized definition for each static data member from an illegal
  41. program containing only declarations, no definitions, for each static
  42. data member, since in both cases a bss symbol is created.  It never
  43. used to matter until templates and automatic instantiation came along.
  44.  
  45. Thanks for making me go back and try this again, Dan, and also thanks
  46. for embarrassing me in public. :-) You should already know that I am
  47. perfectly capable of doing that without anyone's help. :-)
  48.  
  49. -steve
  50.  
  51. -- 
  52. Steve Vinoski  (508)436-5904   vinoski@apollo.hp.com
  53. Distributed Object Computing Program
  54. Hewlett-Packard, Chelmsford, MA 01824       These are my opinions.
  55.