This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Fwd: Templates with more than one static variable]
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: [Fwd: Templates with more than one static variable]
- From: Dean Foster <foster at compstat dot wharton dot upenn dot edu>
- Date: Wed, 31 Mar 1999 22:14:23 -0500
This looks like a bug in egcs. It also has problems if the template static
variable is asigned from a function evalutation like:
int problems<T>::s_i = f(10);
The problem is in egcs 1.0.3
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.29/specs
gcc version egcs-2.90.29 980515 (egcs-1.0.3 release)
thanks,
dean
Dean Foster wrote:
>
> I was wondering if the following is a error in my thinking or a bug in egcs.
> Basically what happens is that if you have all the following:
>
> (1) two static variables
> (2) one variable depends on the other for its value
> (3) you explicitely instantiate the template
>
> then it claims the variables are multiply defined. So the following code
> doesn't run:
>
> #include <iostream.h>
>
> template<class T>
> class problems
> {
> public:
> static int s_i;
> static int s_j;
> };
>
> template<class T>
> int problems<T>::s_i = 7;
>
> template<class T>
> int problems<T>::s_j = 2*s_i; // replacing this with 14 works
>
> template class problems<int>;
>
> main()
> {
> cout << problems<int>::s_i << endl;
> cout << problems<int>::s_j << endl;
> };
>
>
> thanks,
>
> dean
>
> (Dean Foster, Dept of Statistics, Wharton, U. of Penn)
>
> [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
> [ about comp.lang.c++.moderated. First time posters: do this! ]
- Subject: Templates with more than one static variable
- From: Dean Foster <foster at compstat dot wharton dot upenn dot edu>
- Date: 31 Mar 1999 15:17:09 -0500
- Approved: kuehl@fmi.uni-konstanz.de
- Newsgroups: comp.lang.c++.moderated
- Organization: University of Pennsylvania
- References: <372c6077.362475722@nntp.ix.netcom.com>
- Xref: nntp.upenn.edu comp.lang.c++.moderated:40884
I was wondering if the following is a error in my thinking or a bug in egcs.
Basically what happens is that if you have all the following:
(1) two static variables
(2) one variable depends on the other for its value
(3) you explicitely instantiate the template
then it claims the variables are multiply defined. So the following code
doesn't run:
#include <iostream.h>
template<class T>
class problems
{
public:
static int s_i;
static int s_j;
};
template<class T>
int problems<T>::s_i = 7;
template<class T>
int problems<T>::s_j = 2*s_i; // replacing this with 14 works
template class problems<int>;
main()
{
cout << problems<int>::s_i << endl;
cout << problems<int>::s_j << endl;
};
thanks,
dean
(Dean Foster, Dept of Statistics, Wharton, U. of Penn)
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]