home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!ukma!netsys!decwrl!borland.com!pete
- From: pete@borland.com (Pete Becker)
- Subject: Re: Recursive templates
- Message-ID: <1992Nov16.220526.21566@borland.com>
- Originator: pete@genghis.borland.com
- Sender: news@borland.com (News Admin)
- Organization: Borland International
- References: <83733@ut-emx.uucp>
- Date: Mon, 16 Nov 1992 22:05:26 GMT
- Lines: 32
-
- In article <83733@ut-emx.uucp> jamshid@emx.cc.utexas.edu (Jamshid Afshar) writes:
- >Has ANSI decided anything about the expansion of a recursive template
- >definition?
-
- template <unsigned n> class Factorial
- {
- public:
- unsigned eval() { return n*Factorial<n-1>.eval(); }
- };
-
- class Factorial<0>
- {
- public:
- unsigned eval() { return 1; }
- };
-
- #include <iostream.h>
-
- int main()
- {
- Factorial<6> f6;
- cout << f6.eval() << endl;
- return 0;
- }
-
- That's from memory, so I may have some of the details wrong, but it
- worked in BC 3.0, and from discussions I've had the same sort of thing works
- with cfront.
- -- Pete
-
-
-
-