changkun / modern-cpp-tutorial

📚 Modern C++ Tutorial: C++11/14/17/20 On the Fly | https://changkun.de/modern-cpp/
https://changkun.de/modern-cpp/
MIT License
24.1k stars 3k forks source link

A small discriminative modification to the nature of override and overload #265

Closed lingkerio closed 1 year ago

lingkerio commented 1 year ago

resolve #264

Description

The purpose of the PR is to point out a little difference between override and overload to prevent people who don't know who get it wrong. The virtual function of override must be a virtual function with a function signature consistent with the basis function, and overload only needs the function name to be consistent (of course, the overload of the virtual function also needs to satisfy the covariance of the return type)

Change List

Reference

Please add reference if necessary


说明

PR的目的是指明override和overload 的一点区别,以防止不清楚的人搞错。override的虚函数必须是基函数有函数签名与之一致的虚函数才可以,而overload只需要函数名一致(当然虚函数的重载还需要满足返回类型的协变)

变化箱单

参考文献

如果有请注明