#include <iostream>
template <typename T>
class rhsex
{
T _re, _im;
public:
rhsex(T re = 0, T im = 0) :_re{re}, _im{im} {};
~rhsex() {}
rhsex<T>& operator=(const rhsex& rhs)
{
if (this == &rhs)
return *this;
_re = rhs._re; //removed this.
_im = rhs._im; //remove this.
return *this;
}
rhsex<T> operator+(const rhsex<T>& rhs)
{ rhsex<T> temp;
temp._re = _re + rhs._re; temp._im = _im + rhs._im;
return temp;//added this semicolon
}
friend std::ostream& operator<<(std::ostream& os, const rhsex<T>& rhs)
{ os << rhs._re << " * i " << rhs._im;
return os;
}
};
template <typename T>
T suma(T a, T b)
{
return a + b;
}
template <template<typename> typename T, typename U>
void suma(T<U> a, T<U> b)
{
T<U> temp;
temp = a + b;
std::cout << temp;
}
int main()
{
int a1{ 1 }, b1{ 3 };
std::cout << "Suma de int : " << suma<int>(a1, b1) << std::endl;
double a2{ 2.1 }, b2{ 5.9 };
std::cout << "Suma de double: " << suma<double>(a2, b2) << std::endl;
rhsex<int> c1(3, 5), c2(8, 9);
std::cout << "Suma rhse int: ";
suma<rhsex, int>(c1, c2);
return 0;
}