fork download
  1. #include <cmath>
  2.  
  3. template<typename X> class A {
  4. X a;
  5. public:
  6. A(X x) : a(x) {}
  7. template<typename Y>
  8. auto diff(A<Y> const&y) const -> decltype(a-y.a)
  9. { return a-y.a; }
  10. };
  11.  
  12. template<typename X, typename Y>
  13. inline auto dist(A<X> const&x, A<Y> const&y) -> decltype(std::abs(x.diff(y)))
  14. { return std::abs(x.diff(y)); }
  15.  
  16. int main()
  17. {
  18. A<double> x(2.0), y(4.5);
  19. return (int) dist(x,y);
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:19:28: error: within this context
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:19:28: error: within this context
prog.cpp: In function 'decltype (std::abs(x->diff(y))) dist(const A<X>&, const A<Y>&) [with X = double, Y = double, decltype (std::abs(x->diff(y))) = double]':
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:19:28: error: within this context
prog.cpp: In function 'int main()':
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:19:28: error: within this context
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:19:28: error: within this context
prog.cpp: In function 'decltype (std::abs(x->diff(y))) dist(const A<X>&, const A<Y>&) [with X = double, Y = double, decltype (std::abs(x->diff(y))) = double]':
prog.cpp:19:28:   instantiated from here
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:13:17: error: within this context
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:13:17: error: within this context
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:14:32: error: within this context
prog.cpp:4:9: error: 'double A<double>::a' is private
prog.cpp:14:32: error: within this context
stdout
Standard output is empty