Topic: Question concerning static members of templates
Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Sun, 19 Sep 1993 09:55:05 GMT Raw View
In article <27g930$13m@agate.berkeley.edu> hilfinger@CS.Berkeley.EDU writes:
>In article <rfgCDJIy4.346@netcom.com>, rfg@netcom.com (Ronald F. Guilmette) writes:
>> In article <27dplp$hse@agate.berkeley.edu> hilfinger@CS.Berkeley.EDU writes:
>> >
>> >Is it possible to arrange for automatic initialization of a static
>> >data member of a template class?
>>
>> The answer is a qualified yes. It is possible on most (but not necessarily
>> all) implementations.
>
>I'm sorry not to have been clearer in my question. I was aware that
>there is no problem on some implementations; indeed my question was
>prompted by code distributed with a certain textbook that would
>compile on some systems but not others. The syntax Mr. Guilmette
>supplies in his response is indeed the one that was used in this code:
>
>> template <class T> struct TMPL
>> {
>> static T member;
>> };
>>
>> template <class T> T TMPL<T>::member = 0;
>
>My problem is that his P.S. appears to be wrong:
>
>> P.S. There isn't so much as a word about any of this in the ARM. Section
>> 14.8c says that you may *have* static data members in templates, but it
>> never tells you how you are supposed to get the bloody things defined.
>
>Alas, the sections I quoted from the C++ Prog. Lang., 2nd edition DO
>say something about all this---namely that Mr. Guilmette's
>reasonable-looking solution is illegal. Therefore my REAL questions
>are "Have I misread something? Is the situation going to change? If
>so, to what?"
Sorry. I had misunderstood your question the first time around.
You provided the following quote from r14.1 of the C++ Prog. Lang., 2nd ed:
"The declaration in a template-declaration must declare or define
a function or class."
That's where the problem is. That statement is just flat out wrong.
(Not surprizingly, that exact same statement is *also* still present in
the most recent X3J16 draft standard! Anyway, in all of the places it
is currently written, it is just plain wrong.)
--
-- Ronald F. Guilmette ------------------------------------------------------
------ domain address: rfg@netcom.com ---------------------------------------
------ uucp address: ...!uunet!netcom.com!rfg -------------------------------