#include <iostream>
using namespace std;
template <typename T>
class Test {
public:
Test(const T &val) : m_val(val) {}
// Test<T> operator +(const Test<T> &other) {
// return Test(m_val + other.m_val);
// }
const T& val() const { return m_val; }
template <typename N>
friend Test<N> operator +(const Test<N> &a, const Test<N> &b);
private:
T m_val;
};
template <typename T>
Test<T> operator +(const Test<T> &a, const Test<T> &b) {
return Test<T>(a.m_val + b.m_val);
}
int main() {
Test<int> t1(2);
Test<int> t2(2);
Test<int> t3 = t1 + t2;
cout << "Sum is: " << t3.val() << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGUgPHR5cGVuYW1lIFQ+CmNsYXNzIFRlc3QgewpwdWJsaWM6CiAgICBUZXN0KGNvbnN0IFQgJnZhbCkgOiBtX3ZhbCh2YWwpIHt9CgovLyAgICAgVGVzdDxUPiBvcGVyYXRvciArKGNvbnN0IFRlc3Q8VD4gJm90aGVyKSB7Ci8vICAgICAgICAgcmV0dXJuIFRlc3QobV92YWwgKyBvdGhlci5tX3ZhbCk7Ci8vICAgICB9CgogICAgY29uc3QgVCYgdmFsKCkgY29uc3QgeyByZXR1cm4gbV92YWw7IH0KCiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgTj4KICAgIGZyaWVuZCBUZXN0PE4+IG9wZXJhdG9yICsoY29uc3QgVGVzdDxOPiAmYSwgY29uc3QgVGVzdDxOPiAmYik7Cgpwcml2YXRlOgogICAgVCBtX3ZhbDsKfTsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPgpUZXN0PFQ+IG9wZXJhdG9yICsoY29uc3QgVGVzdDxUPiAmYSwgY29uc3QgVGVzdDxUPiAmYikgewogICAgcmV0dXJuIFRlc3Q8VD4oYS5tX3ZhbCArIGIubV92YWwpOwp9CgppbnQgbWFpbigpIHsKICAgIFRlc3Q8aW50PiB0MSgyKTsKICAgIFRlc3Q8aW50PiB0MigyKTsKICAgIFRlc3Q8aW50PiB0MyA9IHQxICsgdDI7CgogICAgY291dCA8PCAiU3VtIGlzOiAiIDw8IHQzLnZhbCgpIDw8IGVuZGw7CgogICAgcmV0dXJuIDA7Cn0K