fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. template<int N, int D>
  5. struct Modulus
  6. {
  7. static auto const value = N % D;
  8. };
  9.  
  10. template<int N>
  11. struct Angle
  12. {
  13. static auto const value = Modulus<N, 360>::value; // ERROR
  14. //static int const value = Modulus<N, 360>::value; // OK
  15. //static auto const value = N % 360; // OK
  16.  
  17. typedef Angle<value> type;
  18. };
  19.  
  20. int main()
  21. {
  22. std::cout << typeid(Angle<30>::type).name() << "\n";
  23. std::cout << typeid(Angle<390>::type).name() << "\n";
  24.  
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'Angle<30>':
prog.cpp:22:38:   instantiated from here
prog.cpp:13:52: error: declaration of 'const auto Angle<30>::value' has no initializer
prog.cpp:13:52: error: invalid in-class initialization of static data member of non-integral type '<type error>'
prog.cpp: In instantiation of 'Angle<30>':
prog.cpp:22:38:   instantiated from here
prog.cpp:17:30: error: could not convert template argument 'Angle<30>::value' to 'int'
prog.cpp: In instantiation of 'Angle<390>':
prog.cpp:23:39:   instantiated from here
prog.cpp:13:52: error: declaration of 'const auto Angle<390>::value' has no initializer
prog.cpp:13:52: error: invalid in-class initialization of static data member of non-integral type '<type error>'
prog.cpp: In instantiation of 'Angle<390>':
prog.cpp:23:39:   instantiated from here
prog.cpp:17:30: error: could not convert template argument 'Angle<390>::value' to 'int'
stdout
Standard output is empty