home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: moudgill@cs.cornell.edu ( Mayan Moudgill)
- Subject: Help! Possibly another bug with templates
- Message-ID: <1993Jan6.221403.24717@cs.cornell.edu>
- Keywords: templates, cfront 3.0, bug, help
- Organization: Cornell Univ. CS Dept, Ithaca NY 14853
- Date: Wed, 6 Jan 1993 22:14:03 GMT
- Lines: 51
-
- The problem that occurs is that the template constructor for objects
- in GLOBAL scope that INHERIT from a template with a STATIC NON-FUNCTION
- member are called too many times.
-
- This can be exhibited by compiling the following file WITH
- THE -ptn OPTION. (or by breaking it up into multiple files).
-
- Question: Is this because the definition of the static non-function
- member using a template is illegal?
-
- The contructor gets called twice instead of once,
- once from the main file, and once from the file inside
- the ptrepository. Is this what should be happening?
-
- The constructor gets called once if
- * the object is non-global.
- * the function contains a static function member, but not a non-function member
- * the static non-function member is explicitly declared.
-
- :)
- Mayan
- (moudgill@cs.cornell.edu)
-
- ----------------- CUT HERE-----------------
- #include<iostream.h>
-
- /* in file A.H */
- template <class T>
- class A {
- private:
- static int n;
- public:
- A()
- {
- cerr << "constructor called" << endl;
- }
- };
-
- /* in file A.C */
- template<class T>
- int A<T>::n;
-
- /* in file use.C */
- class B : public A<B> {
- };
-
- B EEEE;
-
- main()
- {
- }
-