Object returning its field possible?
古いコメントを表示
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!
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Scope Variables and Generate Names についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!