home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18705 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.2 KB  |  51 lines

  1. Path: sparky!uunet!spool.mu.edu!sol.ctr.columbia.edu!ira.uka.de!fauern!rz.unibw-muenchen.de!stefans
  2. From: stefans@bauv.unibw-muenchen.de (Stefan Schwarz)
  3. Newsgroups: comp.lang.c++
  4. Subject: Template-instantiation fails with references
  5. Date: 5 Jan 93 11:55:49 GMT
  6. Organization: University of the armed forces, Munich
  7. Lines: 40
  8. Message-ID: <stefans.726234949@bauv106>
  9. NNTP-Posting-Host: bauv106.bauv.unibw-muenchen.de
  10.  
  11. Hi all,
  12.  
  13. just came to a serious problem with templates. Simple code:
  14.  
  15. #include <iostream.h>
  16. template <class T> class Collection
  17. {
  18. private:
  19.         T *_buffer;
  20.         T _endtag;
  21. public:
  22.         Collection (size_t size, T endtag) {
  23.                 _buffer = new T [size];
  24.                 _endtag = endtag; }
  25. };
  26.  
  27. class Foo
  28. {
  29. };
  30.  
  31. main()
  32. {
  33.         Foo end;
  34.         Collection<Foo&> coll (10,end);
  35. }
  36.  
  37. This fails with:
  38. line 3: error:  reference member  Collection <Foo&>::_endtag needs initializer
  39.  
  40. Replacing Foo& with Foo* (and end with &end) succeeds.
  41.  
  42. So, is there a chance to get my template used with references?
  43.  
  44. BTW: I'm using C++ 3.0 on SGI Irix 4.0.5
  45.  
  46.     Stefan
  47. --
  48. Stefan Schwarz                            University of the armed forces
  49. Laboratory for graphical data processing  W-8014 Neubiberg, FRG
  50. --
  51.