home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17924 < prev    next >
Encoding:
Text File  |  1992-12-14  |  1.9 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: Templates
  5. Message-ID: <1992Dec14.173119.5319@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <1992Dec13.231649.4904@news.cs.brandeis.edu>
  10. Date: Mon, 14 Dec 1992 17:31:19 GMT
  11. Lines: 39
  12.  
  13. In article <1992Dec13.231649.4904@news.cs.brandeis.edu> dernis@binah.cc.brandeis.edu writes:
  14. >Hi,
  15. >  This is a fairly simple template question, I hope.
  16. >I have written a template class, which has been tested and
  17. >appears to work (mostly at least).  Now I tried to use and I 
  18. >have found a problem.
  19. >
  20. >The class is a matrix class, and works with all numerical types
  21. >(I have only tested the two that I need - but presumably).
  22. >
  23. >Now I want to declare a function which returns a complex Matrix.
  24. >
  25. >So I wrote,
  26. >
  27. >Matrix<complex> function();
  28. >
  29. >But I discovered a problem immediately, that this interprets this
  30. >as instance of Matrix<complex>, not a function declaration.  It now
  31. >occurs to me that indeed that is exactly what I have written, and
  32. >it rightfully complains that I left out the arguments.
  33. >
  34.  
  35.     The declaration above declares a function named 'function' that takes
  36. no parameters and returns a value of type Matrix<complex>.  It's just like
  37. a function declaration that does not use templates:
  38.  
  39.     int function();
  40.  
  41.     Either the compiler is confused or there's some missing context in
  42. the original posting.  Oh, one thing that could cause confusion is if the
  43. compiler doesn't know about the Matrix template at the point where this
  44. declaration occurs.  If so, it needs a forward reference:
  45.  
  46.     template <class T> class Matrix;
  47.     Matrix<complex> funcion();
  48.  
  49. If the template has already been seen in the same source file, the forward
  50. reference isn't needed.
  51.     -- Pete
  52.