home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18774 < prev    next >
Encoding:
Text File  |  1993-01-06  |  1.6 KB  |  62 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!sol.ctr.columbia.edu!usc!rpi!batcomputer!cornell!moudgill
  3. From: moudgill@cs.cornell.edu ( Mayan Moudgill)
  4. Subject: Help! Possibly another bug with templates
  5. Message-ID: <1993Jan6.221403.24717@cs.cornell.edu>
  6. Keywords: templates, cfront 3.0, bug, help
  7. Organization: Cornell Univ. CS Dept, Ithaca NY 14853
  8. Date: Wed, 6 Jan 1993 22:14:03 GMT
  9. Lines: 51
  10.  
  11. The problem that occurs is that the template constructor for objects
  12. in GLOBAL scope that INHERIT from a template with a STATIC NON-FUNCTION
  13. member are called too many times.
  14.  
  15. This can be exhibited by compiling the following file WITH
  16. THE -ptn OPTION. (or by breaking it up into multiple files).
  17.  
  18. Question: Is this because the definition of the static non-function
  19. member using a template is illegal?
  20.  
  21. The contructor gets called twice instead of once,
  22. once from the main file, and once from the file inside
  23. the ptrepository. Is this what should be happening?
  24.  
  25. The constructor gets called once if
  26.  * the object is non-global.
  27.  * the function contains a static function member, but not a non-function member
  28.  * the static non-function member is explicitly declared.
  29.  
  30. :)
  31. Mayan
  32. (moudgill@cs.cornell.edu)
  33.  
  34. ----------------- CUT HERE-----------------
  35. #include<iostream.h>
  36.  
  37. /* in file A.H */
  38. template <class T>
  39. class A {
  40. private:
  41.    static int n;
  42. public:
  43.       A()
  44.    {
  45.       cerr << "constructor called" << endl;
  46.    }
  47. };
  48.  
  49. /* in file A.C */
  50. template<class T>
  51. int         A<T>::n;
  52.  
  53. /* in file use.C */
  54. class B : public A<B> {
  55. };
  56.  
  57. B EEEE;
  58.  
  59. main()
  60. {
  61. }
  62.