Tuesday, July 04, 2006

Re :Recursion

Hi Folks you might have read my previous mail on recursion ,so here iam presenting one more great way of doing it using class template :-
template <"int N">
class Fact {
public:
enum { value = N * Fact::value };
};
//Template specialization
class Fact<1> {
public:
enum { value = 1 };
};

make a obj of Factorial and then retreive the value ,the good thing is no function call is made only expansion at runtime is hapening and its an crisp code ,
Template is very powerful in scientific computing .
You can expect more intresting posts on template shortly.

2 comments:

Anonymous said...

Very interesting post,had never used templates this way !!

FarPointer said...

Yes , and this comes under metaprograming and is the basis of BLITZ compilers.