Created
September 9, 2014 19:19
-
-
Save VitaminaCPP/896c5d441c1290c0f271 to your computer and use it in GitHub Desktop.
This file contains 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
template <unsigned int ITERACION> struct Fibonacci | |
{ | |
static const unsigned int valor = | |
Fibonacci<ITERACION - 1>::valor + | |
Fibonacci<ITERACION - 2>::valor; | |
}; | |
template <> struct Fibonacci<1> | |
{ | |
static const unsigned int valor = 1; | |
}; | |
template <> struct Fibonacci<0> | |
{ | |
static const unsigned int valor = 0; | |
}; | |
unsigned int diez() { return 10; } | |
// Los valores de plantilla necesitan ser constantes | |
// en tiempo de compilacion: | |
auto v1 = Fibonacci<10>::valor; | |
// Error de compilacion: diez() no es una constante | |
// en tiempo de compilacion | |
auto v2 = Fibonacci<diez()>::valor; | |
// La cantidad de elementos debe ser una constante | |
// en tiempo de compilacion: | |
int valores1[55] = { 0 }; | |
// Error de compilacion: la variable v1 no | |
// es una constante en tiempo de compilacion: | |
int valores1[v1] = { 0 }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment