operator overloading: class*number vs number*class
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Javier Ros
el 29 de Ag. de 2018
Comentada: Steven Lord
el 29 de Ag. de 2018
Hello,
I've defined a class (lets say vector) and I want to be able to overload the following binary operations
1) >> my_class*number
2) >> number*my_class
I have overloaded mtimes, and then case 1) works (I detect the type of the second operator and proceed accordingly), but case 2) does not. In fact the mtimes function of the class does not get called in case 2).
This may seem as logical, but in cannot figure out a work arround for 2).
How do I program behavior for case 2), that is number*my_class ?.
Thanks,
Javier
0 comentarios
Respuesta aceptada
Más respuestas (1)
Javier Ros
el 29 de Ag. de 2018
Editada: Javier Ros
el 29 de Ag. de 2018
1 comentario
Steven Lord
el 29 de Ag. de 2018
No, this is not a bug.
I assume you posted this answer before posting the one that you ultimately accepted, as in the accepted answer you successfully identified how to obtain the behavior you wanted. The comment I posted to that accepted answer points to the documentation page that explains why you see this behavior.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!