home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16734 < prev    next >
Encoding:
Text File  |  1992-11-22  |  986 b   |  39 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!stanford.edu!rutgers!concert!uvaarpa!murdoch!virginia.edu!gs4t
  2. From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: template member func:  class X { template<class T> f(T& x) {...}}
  5. Message-ID: <1992Nov22.210314.18135@murdoch.acc.Virginia.EDU>
  6. Date: 22 Nov 92 21:03:14 GMT
  7. References: <mg.722310420@elan>
  8. Sender: usenet@murdoch.acc.Virginia.EDU
  9. Organization: University of Virginia
  10. Lines: 27
  11.  
  12. mg@elan (Michael Golan) writes:
  13. : Why isnt this allowed?
  14. : class File {
  15. :     binwrite(void *buf,size_t sz) {...} // write buf of length sz 
  16. : public:
  17. :     template<class T> write(T& buf) { binwrite(buf,sizeof(T)); }
  18. : };
  19.  
  20. Because there is an alternate way to do the same.
  21.  
  22. template <class T>
  23. class File {
  24.     void binwrite(void* buf, int sz) {}
  25. public:
  26.     void write(T* b) { binwrite(b, sizeof(T)); }
  27. };
  28.  
  29. main()
  30. {
  31.     File<int> f;
  32.     int     i = 0;
  33.  
  34.     f.write(&i);
  35. }
  36.  
  37. -Sekar
  38.