Topic: Initialization of Static Components of a Template Class
Author: scherrey@proteus-tech.com (Benjamin Scherrey)
Date: 1996/01/12 Raw View
In message <4cr2m1$1kcq@news.gate.net> - solution@gate.net (Ken Walter) writes:
:>template<class T> int SOMEclass::AStatic(0);
:>
:>and have it automaticaly expanded by the compiler with the template class.
:>
:>Requiring the users of the template class to initialize ever class instance
:>is very inconvenient!
Very true - this is most inconvenient but has been required by every
compiler I've used. It *is* my understanding, however that the following code
(and your example above) are officially supported so compilers should be
letting us do this Real Soon Now.
--- code ----
template< class T > int SOMEClass< T >::AStatic; // Note - statics are
// initialized to zero
// or their equivalent.
// Don't put an explicit 0
// in your templates!
--- end code ---
Regards,
Ben Scherrey
scherrey@proteus-tech.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Author: solution@gate.net (Ken Walter)
Date: 1996/01/08 Raw View
If I have a template class such as:
template<class T> SOMEclass
{
..
private:
static int AStatic;
}
I would like to also be able to say in the header file:
template<class T> int SOMEclass::AStatic(0);
and have it automaticaly expanded by the compiler with the template class.
Requiring the users of the template class to initialize ever class instance
is very inconvenient! It almost forces one to use a macro:
#define SOMEclassSTATICS( T ) int SOMEclass<T>::AStatic(0); /
// other initialization of SOMEclass statics
Or am I missing somrthing from the latest language definition?
Ken Walter
* All the above is hearsay and the opinion of nobody in particular
Author: Etay_Bogner@mail.stil.scitex.com (Etay Bogner)
Date: 1996/01/09 Raw View
In article <4cr2m1$1kcq@news.gate.net>, solution@gate.net (Ken Walter) wrote:
>> template<class T> int SOMEclass::AStatic(0);
change it to :
template<class T> int SOMEclass<T>::AStatic = 0; // = 0 is clearer for int's
^^^
This is legal for quite some time now, and actually, I don't know why it
passed the moderation, since it's surely a FAQ.
--
-- Etay Bogner,
-- Etay_Bogner@mail.stil.scitex.com,
-- Scitex Corp.
-- Israel.
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]