I'm doing a program in C ++ that overload the operators. For example, for the operator *
you would like it to be multiplied:
Cuadrado a(2.1);
Circulo b(1.3);
Circulo b(4.3);
Triangulo x= a * b * c
I have created the operation Cuadrado*Circulo
but when assigning the result to the variable x that is of the triangle type, it indicates the following:
No Suitable User Defined Conversión from Cuadrado to Triangulo.
How can I convert a square type to a triangle?
template < int DIM1, int DIM2>
class Forma
{
double value;
public:
int a;
int b;
Forma(double in) : value(in) {
a = DIM1, b = DIM2;
}
//Getters
const double get_data() const { return value; }
//Setters
const void set_data(double d) {value=d; }
};
//Multiplication
template<class Cuadrado, class Circulo>
Circulo operator*(Cuadrado left, Circulo right)
{
Circulo result (left.get_data() * right.get_data());
return result;
}
using Cuadrado = Forma < 1, 1 >;
using Triangulo = Forma < 1, 2 > ;
using Circulo = Forma < 1, 3 > ;
These types are created from the template of the class Forma
.