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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!noc.near.net!news.cs.brandeis.edu!binah.cc.brandeis.edu!DERNIS
  3. From: dernis@binah.cc.brandeis.edu
  4. Subject: Templates
  5. Message-ID: <1992Dec13.231649.4904@news.cs.brandeis.edu>
  6. Sender: news@news.cs.brandeis.edu (USENET News System)
  7. Reply-To: dernis@binah.cc.brandeis.edu
  8. Organization: Brandeis University
  9. Date: Sun, 13 Dec 1992 23:16:49 GMT
  10. Lines: 33
  11.  
  12. Hi,
  13.   This is a fairly simple template question, I hope.
  14. I have written a template class, which has been tested and
  15. appears to work (mostly at least).  Now I tried to use and I 
  16. have found a problem.
  17.  
  18. The class is a matrix class, and works with all numerical types
  19. (I have only tested the two that I need - but presumably).
  20.  
  21. Now I want to declare a function which returns a complex Matrix.
  22.  
  23. So I wrote,
  24.  
  25. Matrix<complex> function();
  26.  
  27. But I discovered a problem immediately, that this interprets this
  28. as instance of Matrix<complex>, not a function declaration.  It now
  29. occurs to me that indeed that is exactly what I have written, and
  30. it rightfully complains that I left out the arguments.
  31.  
  32. Does this mean at that I have to template this function too, and do 
  33. something like:
  34.  
  35. template <class T>
  36. void function(Matrix<T>& ref_to_value);
  37.  
  38. Is there a way I can write a function that will return a complex
  39. instance of my matrix class without writing the function as a template.
  40. The above my be acceptable, even better as it does not generate a 
  41. temporary, but still. . .
  42.  
  43. Thanks,
  44. Mitch Dernis
  45.