fork download
  1. #include<iostream>
  2.  
  3. class Point
  4. {
  5. public:
  6. int X, Y;
  7. mutable int Z;
  8.  
  9. constexpr Point(int x, int y) :X (x), Y(y), Z(0)
  10. { }
  11.  
  12. constexpr int GetX() const
  13. {
  14. // Z++;
  15. return X+Z;
  16. }
  17.  
  18. int GetY() const
  19. {
  20. Z++;
  21. return Y;
  22. }
  23.  
  24. void FoolConst() const
  25. {
  26. Z++;
  27. }
  28. };
  29.  
  30. constexpr int foo()
  31. {
  32. return 0;
  33. }
  34.  
  35. template<int S>
  36. void foo()
  37. {
  38. std::cout<<S << std::endl;
  39. }
  40.  
  41. int main()
  42. {
  43. constexpr Point pt(10, 20);
  44.  
  45. pt.FoolConst();
  46.  
  47. foo<pt.GetX()>();
  48.  
  49. std::cout << pt.GetX();
  50. }
Compilation error #stdin compilation error #stdout 0s 3412KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:47:17: error: no matching function for call to 'foo()'
  foo<pt.GetX()>();
                 ^
prog.cpp:36:6: note: candidate: template<int S> void foo()
 void foo()
      ^
prog.cpp:36:6: note:   template argument deduction/substitution failed:
prog.cpp:47:13:   in constexpr expansion of 'pt.Point::GetX()'
prog.cpp:47:17: error: mutable 'Point::Z' is not usable in a constant expression
  foo<pt.GetX()>();
                 ^
prog.cpp:47:17: note: in template argument for type 'int' 
stdout
Standard output is empty