* Static variables in templates
@ 2002-05-31 17:19 Ravikiran Rajagopal
0 siblings, 0 replies; only message in thread
From: Ravikiran Rajagopal @ 2002-05-31 17:19 UTC (permalink / raw)
To: gcc
Hello,
I cannot initialize static variables in templates on HPUX 11. The following
code compiles and works as you would expect it to on Linux, but fails with a
linker error in HPUX. The error message follows the program listing. My
compiler version is gcc-3.1 (built from sources) with binutils-2.12 (built
from sources).
--- test.cc ---
// Template definition
template<class T>
class foo
{
public:
foo(T v) : var(v) { times++; };
T var;
static int times;
};
template<class T>
int foo<T>::times = 0;
// Now we use this template.
int main( int , char ** )
{
foo<int> a(23);
return 0;
}
---------------
On HPUX, it fails with the following linker error:
---------------
eehp015:~/misc> gcc -o test test.cc
/usr/ccs/bin/ld: Unsatisfied symbols:
foo<int>::times (first referenced in /var/tmp//ccikfnVs.o) (data)
collect2: ld returned 1 exit status
---------------
Any pointers would be greatly appreciated. This construct is very important,
because large parts of KDE 3.x code depend on it. I am trying to port KDE 3.x
to HPUX with gcc 3.1 release. Please cc any replies/follow-ups to me as I am
not subscribed to the list. In case this is the wrong place to ask this
question, I apologize and request you to kindly direct me to the right fora.
Thank you,
Ravi
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-05-31 21:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-31 17:19 Static variables in templates Ravikiran Rajagopal
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).