home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:18504 gnu.g++.help:1617
- Newsgroups: comp.lang.c++,gnu.g++.help
- Path: sparky!uunet!cs.utexas.edu!torn!skule.ecf!drill.me!zougas
- From: zougas@me.utoronto.ca (Tom Zougas)
- Subject: static member initialization
- Message-ID: <C01An8.2E1@me.utoronto.ca>
- Sender: news@me.utoronto.ca (News Reader)
- Organisation: U of Toronto, Dept. of Mechanical Engineering
- Organization: UofT Mechanical Engineering
- Distribution: comp
- Date: Tue, 29 Dec 1992 18:42:44 GMT
- Lines: 57
-
- I'm using gcc-2.3.2 on a Sparc, Sun OS4.1.1 and am having difficulties
- with the following situation:
-
- I declare a template class which contains a static member. When I try
- to initialize the static member, it doesn't work unless I do it inside
- the scope of 'main'. Static members of non-template classes can be
- initialized outside the scope of 'main' and I would expect the same
- for template classes. Is this how template classes work or is it a
- bug in the gcc compiler? Please e-mail any responses. Thanks.
-
- The following is the test code I used:
-
- // beginning of included file: test.cc
- ////////////////////////////////////////////////////////////////
- #include <iostream.h>
-
- class Int {
- public:
- Int( int i ) { _i = i; }
- void print() { cout << _i << endl; }
- int _i;
- };
-
- class _Test {
- public:
- _Test() {}
- void print() { x.print(); }
- static Int x;
- };
-
- template <class Type>
- class Test : public _Test {
- public:
- void print() { _Test::print(); x.print(); }
- static Int x;
- };
-
- Int _Test::x(99);
- //Int Test<int>::x(88); // <=== this is where I want to initialize
- // but doesn't work
-
- main()
- {
- Int Test<int>::x(88); // <=== this is where I have to initialize
- // to get it to work
- Test<int> ti;
- ti.print();
- test();
- }
-
- ////////////////////////////////////////////////////////////////
- // end of included file
- --
- ===========================================================================
- Tom Zougas zougas@me.utoronto.ca
- Engineering Mechanics and Design Laboratory 416-978-1281
- Dept of Mechanical Engineering, University of Toronto, Toronto, CANADA
-