home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!munnari.oz.au!titan!trlluna!bruce.cs.monash.edu.au!monu6!nella9.cc.monash.edu.au!rik
- From: rik@nella9.cc.monash.edu.au (Rik Harris)
- Subject: template problem (g++)
- Message-ID: <rik.722065099@nella9.cc.monash.edu.au>
- Keywords: bug? g++ template operator
- Sender: news@monu6.cc.monash.edu.au (Usenet system)
- Reply-To: rik.harris@fcit.monash.edu.au
- Organization: Monash University, Melb., Australia.
- Date: Wed, 18 Nov 1992 05:38:19 GMT
- Lines: 60
-
- I'm having a problem with templates, using g++ 2.3.1. It occurs when a
- function template argument is a base class, and a template function
- not being generated when using a derived class (ARM terminology p345).
- In the program below, I believe it should generate a template for
- operator<< for the A<int> type, as B is derived from A<int>, but it
- doesn't seem to. I get the error:
- ld: Undefined symbol
- ___ls__FR7ostreamRt1A1Zi
-
-
- Am I expecting too much from C++, or is this a problem with g++ 2.3.1?
- I have a friend with Borland C++ (a version with templates, not sure
- which one) and he was able to compile this code. If it is
- unreasonable for C++ to automatically generate a template for operator<<,
- is there a way I can coerce it to do so?
-
- // simplified example...don't look too hard at it's usefulness :-)
- #include <stream.h>
-
- template<class T>
- class A
- {
- T a;
- public:
- void set(T b) { a=b; }
- friend ostream& operator << (ostream& s, A<T>& x);
- };
-
- template<class T>
- ostream& operator << (ostream& s, A<T>& x)
- {
- return s << "template: (" << x.a << ")\n";
- }
-
- // it compiles with this line uncommented
- //ostream& operator << (ostream&s, A<int>& x) { return s; }
-
- class B : public A<int>
- {
- int a;
- public:
- void set(int i) { a=i; }
- };
-
- main()
- {
- B b;
-
- b.set(3);
- cout << b;
- }
-
-
- thanks for any help,
- rik.
- --
- Rik Harris - rik.harris@fcit.monash.edu.au
- +61 3 571-2895 (AH & ans.mach) +61 3 573-2679 (BH)
- Faculty of Computing and Information Technology,
- Caulfield Campus, Monash University, Australia
-