Thread View: comp.std.c++
2 messages
2 total messages
Started by Ken Walter
Wed, 29 Nov 1995 18:11
Initialization fo template static components?
Author: Ken Walter
Date: Wed, 29 Nov 1995 18:11
Date: Wed, 29 Nov 1995 18:11
34 lines
1280 bytes
1280 bytes
If I have a template class with static components, it would be nice if the
template instantiator also did likewise expanded static component
initializers. It is very awkward to require users of a template to initialize
private static components when I already know what they should be.
Example:
template< class T> class MYstuff
{
private:
static T* myPtr;
..
}
I would like to say something like:
template <class T> T* MYstuff::myPtr = 0;
and have the compiler generate the initialization when it generates the
particular instance.
Anything like this possible or contemplated?
Ken Walter
* All the above is hearsay and the opinion of nobody in particular
---
[ 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. ]
Re: Initialization fo template static components?
Author: Anil Vijendran
Date: Mon, 04 Dec 1995 16:30
Date: Mon, 04 Dec 1995 16:30
58 lines
2553 bytes
2553 bytes
>>>>> On 29 Nov 1995 18:11:36 GMT, solution@gate.net (Ken Walter)
said:
Ken> If I have a template class with static components, it would be nice if the
Ken> template instantiator also did likewise expanded static component
Ken> initializers. It is very awkward to require users of a template to initialize
Ken> private static components when I already know what they should be.
Ken> Example:
Ken> template< class T> class MYstuff
Ken> {
Ken> private:
Ken> static T* myPtr;
Ken> ..
Ken> }
Ken> I would like to say something like:
Ken> template <class T> T* MYstuff::myPtr = 0;
Ken> and have the compiler generate the initialization when it generates the
Ken> particular instance.
Ken> Anything like this possible or contemplated?
It is already there!
14.13 Static members and variables [temp.static]
2 Static class member templates are defined similarly to member function
templates. [Example:
template<class T> T X<T>::s = 0;
int X<int>::s = 3;
You could try this if your compiler doesn't support the above.
template <class T> class MyStuff
{
private:
static T* getMyPtr();
//...
};
template <class T> T* MyStuff<T>::getMyPtr() {
static T* myPtr;
// initialize myptr;
return myPtr;
}
--
Peace.... +<:-)
Anil
[ 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. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads