Topic: template class static member clarification...
Author: ellis@summit.novell.com (-TEMP-+Ellis M.)
Date: 10 Feb 1994 16:22:36 -0500 Raw View
In article <1994Feb7.142944.10023@cs.cornell.edu> moudgill@cs.cornell.edu ( Mayan Moudgill) writes:
:Supposing I declare a template class with a static member as:
:
: // A.H
: template <class T>
: class A {
: public:
: static int X;
: }
:
:I have to define it; so assume I do it in A.C
: // A.C
: template <class T> int A<T>::X = 10;
:
:Now lets assume I print out its value, as
:
: // main.C
: main()
: {
: A<int> a;
: cerr << a.X << ' ' << A<char>::X << '\n';
: }
:
:I assume I should get 10 10. But I actually get 0 0.
:
:Now:
:1. Is this a cfront 3.0.2 bug? or
:2. Is it illegal to implicitly define and/or initialize template class
: static members, by declaring them in the .C file for the template?
:
:My money's on (1), but since the ARM is not completely clear on the subject
:I thought I'd ask.
:
::)
:Mayan
I get
10 10
from every release of cfront from 3.0 through 3.0.3.
Are you sure you are compiling what you entered here
(with minor corrections like a semicolon after the
template declaration, and the necessary #includes)?
We see no bug in cfront.
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Fri, 11 Feb 1994 12:27:11 GMT Raw View
moudgill@cs.cornell.edu ( Mayan Moudgill) writes:
> template <class T> int A<T>::X = 10;
[...]
>2. Is it illegal to implicitly define and/or initialize template class
> static members, by declaring them in the .C file for the template?
[...]
>My money's on (1), but since the ARM is not completely clear on the subject
>I thought I'd ask.
Actually, the ARM is quite clear on the subject:
"The _declaration_ in a _template-declaration_ must declare
or define a function or a class".
A<T>::X is an int, not a class, so your example is illegal according
to the ARM.
However, I believe that the committee is planning to relax the
rules (or perhaps have already relaxed the rules) on this one.
So your example might well be legal ANSI/ISO C++ eventually.
--
Fergus Henderson - fjh@munta.cs.mu.OZ.AU
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 11 Feb 1994 20:04:36 GMT Raw View
>>>>> Fergus Henderson <fjh@munta.cs.mu.OZ.AU> writes:
> Actually, the ARM is quite clear on the subject:
> "The _declaration_ in a _template-declaration_ must declare
> or define a function or a class".
> A<T>::X is an int, not a class, so your example is illegal according
> to the ARM.
> However, I believe that the committee is planning to relax the
> rules (or perhaps have already relaxed the rules) on this one.
> So your example might well be legal ANSI/ISO C++ eventually.