Problem with static in templates

Marc Winter mwinter@student.uni-kassel.de
Mon Jan 11 05:19:00 GMT 1999


Hello,

if I compile the following "test.cc":

-----------------

template <class T>
class A {
public:
        static int a;
        A() {a=0;}
        void in(T i) {a=i;}
};

template <class T> int A<T>::a = 0;

int main (void)
{
        A<int> b;

        b.in(1);

        return 0;
}

----------------

with: 

	g++ test.cc -o test.exe

I get:
	ld: 0711-317 ERROR: Undefined symbol: A<int>::a
	ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
	information.
	collect2: ld returned 8 exit status
	
I am using (from g++ -v):

	Reading specs from /usr/net/lib/gcc-lib/rs6000-ibm-aix4.2.1.0/egcs-2.91.57/specs
	gcc version egcs-2.91.57 19980901 (egcs-1.1 release)

When I omit the init-parameter of a there are no errors.

Is there anything I can do about this error without greater changes on
the code?

Thanks,

Marc Winter				FGNN GHK Uni-Kassel
------------------------------------------------------------

email: mwinter@student.uni-kassel.de

------------------------------------------------------------




More information about the Gcc-bugs mailing list