This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template <int N> | |
struct fact | |
{ | |
static const int value = N * fact<N - 1>::value; | |
}; | |
template <> | |
struct fact<0> | |
{ | |
static const int value = 1; | |
}; | |
int main() | |
{ | |
std::cout << fact<6>::value << std::endl; | |
std::cout << fact<3>::value << std::endl; | |
return 0; | |
} |
No comments:
Post a Comment