Object returning its field possible?
Mostrar comentarios más antiguos
Hi,
I am writing a class. Is there a way to return one of object's fields, instead of the object itself, when calling it? In other words, I want that my object becomes indistinguishable from double for all practical applications. I want to do this to avoid the need to overload all operators, and ensure all legacy code, which assumes that variables are of type double, can be used without any changes, and can remain compatible with both types.
The closest way I can think of is to overload the uplus operator, which for my class would return one of the fields, while having no effect on double. This will make the code transparent to variable type, but still requires code changes (unary + has to be added in front of each occurence of such variable) and will not be compatible with functions I cannot change e.g., built-in functions. Is there a better way?
Thanks!
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Whos en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!