home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18790 < prev    next >
Encoding:
Internet Message Format  |  1993-01-07  |  1.3 KB

  1. Path: sparky!uunet!cs.utexas.edu!swrinde!sdd.hp.com!spool.mu.edu!think.com!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!corax.udac.uu.se!buzz.bmc.uu.se!perrier!sundvall
  2. From: sundvall@perrier.se (Mats Sundvall)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Template-instantiation fails with referenc
  5. Message-ID: <1ic177INN3k4@buzz.bmc.uu.se>
  6. Date: 5 Jan 93 13:07:51 GMT
  7. References: <stefans.726234949@bauv106>
  8. Reply-To: sundvall@perrier.se
  9. Organization: EMBNet Project Sweden
  10. Lines: 34
  11. NNTP-Posting-Host: perrier.embnet.se
  12.  
  13. In article 726234949@bauv106, stefans@bauv.unibw-muenchen.de (Stefan Schwarz) writes:
  14. >Hi all,
  15. >
  16. >just came to a serious problem with templates. Simple code:
  17. >
  18. >#include <iostream.h>
  19. >template <class T> class Collection
  20. >{
  21. >private:
  22. >        T *_buffer;
  23. >        T _endtag;
  24. >public:
  25. >        Collection (size_t size, T endtag) {
  26. >                _buffer = new T [size];
  27. >                _endtag = endtag; }
  28. >};
  29.  
  30.  
  31.        Collection (size_t size, T endtag) : _endtag(endtag) {
  32.                _buffer = new T [size]; }
  33. };
  34.  
  35.  
  36. >This fails with:
  37. >line 3: error:  reference member  Collection <Foo&>::_endtag needs initializer
  38.  
  39. The reference variable _endtag needs an initializr in the constructor. Try the change 
  40. above.
  41.  
  42. Regrads,
  43.  
  44. Mats Sundvall
  45. Uppsala University
  46. Uppsala, Sweden
  47.