* static template initialization pb
@ 1997-11-30 8:29 neal
1997-11-30 14:29 ` Alexandre Oliva
0 siblings, 1 reply; 2+ messages in thread
From: neal @ 1997-11-30 8:29 UTC (permalink / raw)
To: egcs
I believe the current standard should allow initialization in the
declaration, so this should work:
template<class T>
struct X {
static T c = 0;
};
//template<class T> T X<T>::c = 0;
X<int> W;
#include <iostream.h>
main () {
cout << W.c << endl;
}
-----------------------
Here's what happens with 971127 (linux):
g++ -o Test2 Test2.cc
/tmp/cca002091.o: In function `main':
/tmp/cca002091.o(.text+0x9): undefined reference to `X<int>::c'
collect2: ld returned 1 exit status
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: static template initialization pb
1997-11-30 8:29 static template initialization pb neal
@ 1997-11-30 14:29 ` Alexandre Oliva
0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1997-11-30 14:29 UTC (permalink / raw)
To: neal; +Cc: egcs
writes:
> I believe the current standard should allow initialization in the
> declaration, so this should work:
But this only works for integral types, and definition outside the
class body is still mandatory unless you define a constant. In this
case, the definition must not contain an initialization:
template<class T> T X<T>::c; // = 0;
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-11-30 14:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-30 8:29 static template initialization pb neal
1997-11-30 14:29 ` Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).