language: C++11 (gcc-4.7.2)
date: 338 days 21 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <cmath>
    
    template<typename X> class A {
      X a;
    public:
      A(X x) : a(x) {}
      template<typename Y>
      auto diff(A<Y> const&y) const -> decltype(a-y.a)
      { return a-y.a; }
    };
    
    template<typename X, typename Y>
    inline auto dist(A<X> const&x, A<Y> const&y) -> decltype(std::abs(x.diff(y)))
    { return std::abs(x.diff(y)); }
    
    int main()
    {
      A<double> x(2.0), y(4.5);
      return (int) dist(x,y);
    }
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