Article View: gnu.g++.bug
Article #1039(none)
From: Karsten Pahnke
Date: Fri, 09 Oct 1992 09:03
Date: Fri, 09 Oct 1992 09:03
86 lines
2675 bytes
2675 bytes
/*
Hallo,
it seems to be there is an error in g++ 2.2.2
it is not possible to implement global(not friend)
ostream operators for template classes
the following is a shorthand example of the problem
i thank for your efforts
Karsten
karsten@Inf-Technik.TH-Ilmenau.DE
-----------------------------------------------------------
*/
#include <iostream.h>
template <class T>
class Array {
T* _arr;
int _len;
public:
Array(int len) { _arr = new T[_len = len]; }
int len() const { return _len; }
T& operator[](int i) {return _arr[i]; }
void print(ostream& s) const
{
for ( int i = 0; i < _len; i++ ) {
s << _arr[i] << " ";
}
}
/* version 1 works properly, but friend is not necesssary */
/* thats why version 2 */
/*
friend ostream& operator<<(ostream& s, const Array& a)
{ a.print(s); return s; }
*/
};
/* works properly */
template <class T>
inline int empty(const Array<T>& a)
{
return (a.len() == 0);
}
/* version 2 works with cfront, but not with gnu */
/*
/space/localtmp/gnu/bin/g++ -B/space/localtmp/gnu/lib/gcc/sparc-sun-sunos4.1.1/2.2.2/
-I/space/local/gnu/lib/g++-include -g -DPRECOND -DYYDEBUG -DDEBUG \
-I/home/usr/omsi/work/inc \
-c comp_out.cc
comp_out.cc: In function `int main ()':
comp_out.cc:42: warning: dbx info for template class methods not yet supported
/space/localtmp/gnu/bin/gcc: Internal compiler error: program cc1plus got fatal signal 11
*** Error code 1
make: Fatal error: Command failed for target `comp_out.o'
*/
template <class T>
inline ostream& operator<<(ostream& s, const Array<T>& a)
{
a.print(s); return s;
}
main()
{
Array<int> a(10);
cerr << empty(a) << endl;
cerr << a << endl;
}
--
-----------------------------------------------------------
| Dipl.-Ing. Karsten Pahnke | Telefon : 0037 672 691167 |
| Technische Hochschule Ilmenau | 0037 672 691168 |
| PSF 327, O-6300 Ilmenau | Telefax : 0037 672 691517 |
|-----------------------------------------------------------|
| E-Mail : Pahnke@Inf-Technik.TH-Ilmenau.DE |
-----------------------------------------------------------
Technical Details
Message-ID:
<1992Oct09.090310.5694@th-ilmenau.RZ.TH-Ilmenau.DE>Path:
arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pegasus.inf-technik.th-ilmenau.de!karstenShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!convex!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pegasus.inf-technik.th-ilmenau.de!karsten From: karsten@pegasus.inf-technik.th-ilmenau.de (Karsten Pahnke) Subject: (none) Message-ID: <1992Oct09.090310.5694@th-ilmenau.RZ.TH-Ilmenau.DE> Sender: gnulists@ai.mit.edu Organization: TH Ilmenau/MSS, Germany Distribution: gnu Date: Fri, 9 Oct 1992 09:03:10 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 88