This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

specific instantiation of static members from template class


hello, I have a problem when I try to instantiate static members. this code 
works with gcc-3.4.5 but not with gcc-4.0.2 (debian sid).
here a test case with 3 files :


///// main.cpp
#include <iostream>
#include "Test.h"

int main(int argc, char **argv)
{
	std::cout << TestInt::member << std::endl;
	return 0;
}

///// test.h
template <class T>
class Test
{
public:

	static T member;
};

typedef Test<int> TestInt;

///// test.cpp
#include "Test.h"

template class Test<int>;
template<> int Test<int>::member;


I got an error at link because it cannot find the symbol Test<int>::member 
used in "main.o"
If I use only one file, it works.
If I give an initial value to Test<int>::member in test.cpp, it works.
It works with gcc-3.4.5.

I did some research and see that it could works even without the member 
declaration, the class instantiation should be enough here : 
http://gcc.gnu.org/ml/gcc/2004-05/msg01393.html

Is this a bug or a behavour change from gcc ?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]