fork(4) download
  1. #include <iostream>
  2.  
  3. template<int N>
  4. constexpr int factorial(){
  5. return N*factorial<N-1>();
  6. }
  7. template<>
  8. constexpr int factorial<0>(){
  9. return 1;
  10. }
  11. template<>
  12. constexpr int factorial<1>(){
  13. return 1;
  14. }
  15. struct factorials{
  16. constexpr static int tab[9]{factorial<1>(), factorial<2>(), factorial<3>(), factorial<4>(), factorial<5>(), factorial<6>(), factorial<7>(), factorial<8>(), factorial<9>()};
  17. };
  18.  
  19. int main() {
  20. for(int i=0; i<9; i++){
  21. std::cout << factorials::tab[i] << std::endl;
  22. }
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 3468KB
stdin
Standard input is empty
compilation info
/home/rsANJx/cc5rQ9Rj.o: In function `main':
prog.cpp:(.text.startup+0x17): undefined reference to `factorials::tab'
prog.cpp:(.text.startup+0x3b): undefined reference to `factorials::tab'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty