Just to consider:
#include
template
class base{
public:
T val;
base(T val_arg) : val (val_arg) {}
base& operator+(const base& a)
{
val += a.val;
return *this;
}
};
template
std::ostream& operator<< (std::ostream& s, const base& a)
{
s << a.val;
return s;
}
typedef base my_type_1;
typedef base my_type_2;
int main()
{
my_type_1 v1(1);
my_type_1 v2(2);
my_type_1 res = v1 + v2;
std::cout << res << std::endl;
my_type_1 r1 = v1;
my_type_2 v3(3);
//my_type_1 r2 = v3; // This is a compilation error
//my_type_1 res2 = v1 + v3; // This is a compilation error
//std::cout << res2 << std::endl;
return 0;
}