home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!fauern!rz.unibw-muenchen.de!stefans
- From: stefans@bauv.unibw-muenchen.de (Stefan Schwarz)
- Newsgroups: comp.lang.c++
- Subject: Template-instantiation fails with references
- Date: 5 Jan 93 11:55:49 GMT
- Organization: University of the armed forces, Munich
- Lines: 40
- Message-ID: <stefans.726234949@bauv106>
- NNTP-Posting-Host: bauv106.bauv.unibw-muenchen.de
-
- Hi all,
-
- just came to a serious problem with templates. Simple code:
-
- #include <iostream.h>
- template <class T> class Collection
- {
- private:
- T *_buffer;
- T _endtag;
- public:
- Collection (size_t size, T endtag) {
- _buffer = new T [size];
- _endtag = endtag; }
- };
-
- class Foo
- {
- };
-
- main()
- {
- Foo end;
- Collection<Foo&> coll (10,end);
- }
-
- This fails with:
- line 3: error: reference member Collection <Foo&>::_endtag needs initializer
-
- Replacing Foo& with Foo* (and end with &end) succeeds.
-
- So, is there a chance to get my template used with references?
-
- BTW: I'm using C++ 3.0 on SGI Irix 4.0.5
-
- Stefan
- --
- Stefan Schwarz University of the armed forces
- Laboratory for graphical data processing W-8014 Neubiberg, FRG
- --
-