Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

override キーワードの効果 #82

Closed
SaitoAtsushi opened this issue Nov 29, 2020 · 1 comment · Fixed by #86
Closed

override キーワードの効果 #82

SaitoAtsushi opened this issue Nov 29, 2020 · 1 comment · Fixed by #86

Comments

@SaitoAtsushi
Copy link

オーバーライドするには派生クラスのメンバ関数に override をつけます。

もちろん習慣としては常につけたほうが良いのですが、オーバーライドになるかどうかは同じ名前・同じシグネチャであることがまず基準として有るのでその説明は必要ではないでしょうか。

override キーワードはオーバーライドになってないときに不正ということにするという補助的な機能しかもちませんが、今の説明だと override キーワードを付けることでオーバーライドになるというように読めてしまいます。

@yohhoy
Copy link

yohhoy commented Dec 11, 2020

修正素案です:

派生クラスで仮想関数の挙動を変更することをオーバーライドといいます。 派生クラスでオーバライドを行うには、仮想関数シグニチャ(引数の型やconst修飾の有無)を厳密一致させる必要があります。オーバーライドであることを明確化するため派生クラスのメンバ関数に override 明示が推奨されます。


override は「プログラマのミスや基底クラスの仕様変更により、関数シグニチャが厳密一致しないためオーバーライドに失敗する」事故を防ぐために導入された仕組みです。このような導入経緯に参考言及してもよいかもしれませんね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants