home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!stanford.edu!rutgers!concert!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Newsgroups: comp.lang.c++
- Subject: Re: template member func: class X { template<class T> f(T& x) {...}}
- Message-ID: <1992Nov22.210314.18135@murdoch.acc.Virginia.EDU>
- Date: 22 Nov 92 21:03:14 GMT
- References: <mg.722310420@elan>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Organization: University of Virginia
- Lines: 27
-
- mg@elan (Michael Golan) writes:
- : Why isnt this allowed?
- :
- : class File {
- : binwrite(void *buf,size_t sz) {...} // write buf of length sz
- : public:
- : template<class T> write(T& buf) { binwrite(buf,sizeof(T)); }
- : };
-
- Because there is an alternate way to do the same.
-
- template <class T>
- class File {
- void binwrite(void* buf, int sz) {}
- public:
- void write(T* b) { binwrite(b, sizeof(T)); }
- };
-
- main()
- {
- File<int> f;
- int i = 0;
-
- f.write(&i);
- }
-
- -Sekar
-