home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
- From: pete@borland.com (Pete Becker)
- Subject: Re: Templates
- Message-ID: <1992Dec14.173119.5319@borland.com>
- Originator: pete@genghis.borland.com
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <1992Dec13.231649.4904@news.cs.brandeis.edu>
- Date: Mon, 14 Dec 1992 17:31:19 GMT
- Lines: 39
-
- In article <1992Dec13.231649.4904@news.cs.brandeis.edu> dernis@binah.cc.brandeis.edu writes:
- >Hi,
- > This is a fairly simple template question, I hope.
- >I have written a template class, which has been tested and
- >appears to work (mostly at least). Now I tried to use and I
- >have found a problem.
- >
- >The class is a matrix class, and works with all numerical types
- >(I have only tested the two that I need - but presumably).
- >
- >Now I want to declare a function which returns a complex Matrix.
- >
- >So I wrote,
- >
- >Matrix<complex> function();
- >
- >But I discovered a problem immediately, that this interprets this
- >as instance of Matrix<complex>, not a function declaration. It now
- >occurs to me that indeed that is exactly what I have written, and
- >it rightfully complains that I left out the arguments.
- >
-
- The declaration above declares a function named 'function' that takes
- no parameters and returns a value of type Matrix<complex>. It's just like
- a function declaration that does not use templates:
-
- int function();
-
- Either the compiler is confused or there's some missing context in
- the original posting. Oh, one thing that could cause confusion is if the
- compiler doesn't know about the Matrix template at the point where this
- declaration occurs. If so, it needs a forward reference:
-
- template <class T> class Matrix;
- Matrix<complex> funcion();
-
- If the template has already been seen in the same source file, the forward
- reference isn't needed.
- -- Pete
-