How do I call the built-in disp function after I have overloaded it in a different class?

5 ビュー (過去 30 日間)
Andrew Polston
Andrew Polston 2020 年 3 月 30 日
回答済み: Hakon Haugnes 2023 年 1 月 14 日
Hi, I have two classes PermutationKey and Attack, within both I am overloading the disp function, yet in writing the disp function for Attack and calling
disp(['Key: ' atk.key]);
disp(['Current decrypted ciphertext: ' start]);
it chooses to call the disp function from the class PermutationKey
function disp(key)
disp(char(key.perm + 64));
end
rather than the built-in disp.
Anyone know a remedy for this situation as I simply wish to use the built-in disp function to print to the console the text provided? Thanks

回答 (2 件)

Steven Lord
Steven Lord 2020 年 3 月 30 日
When you concatenate a char vector and an instance of your PermutationKey class, does that return an instance of the PermutationKey class? What does this return?
class(['Key: ' atk.key])
Maybe explicitly convert the key to a character array?
disp(['Key: ' char(atk.key)])

Hakon Haugnes
Hakon Haugnes 2023 年 1 月 14 日
Yes, simply run this
builtin('disp',h)
where h is your class object

カテゴリ

Help Center および File ExchangeAuthor Block Masks についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by