新建/删除“覆盖”与“过载”相比
我一直认为...
- 覆盖意味着在基类中重新实现一个函数(相同的签名),而
- 重载意味着实现一个具有相同名称但不同签名的函数
...并且得到困惑是因为有时人们根本不关心差异。
关于新建/删除:它们是否超载或被覆盖?
一个想法:
- 在类中实现 new/delete 运算符 = 重载
- 重新实现全局 new/delete = 覆盖 有
任何更正/建议/反对吗? 并随意将问题标记为“吹毛求疵”......
I always thought...
- overriding means reimplementing a function (same signature) in a base class whereas
- overloading means implementing a function with same name but different signature
... and got confused because sometimes people just don't care about the difference.
Concerning new/delete: Are they overloaded or overridden?
An idea:
- implementing new/delete operator in a Class = overload
- reimplementing global new/delete = override
Any corrections/suggestions/objections?
And feel free to tag the question "hairsplitting"...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于全局
operator new
和operator delete
来说,它实际上既不是重载也不是重写。程序可以用自己的定义替换默认的、实现提供的定义。 C++ 标准规定 (§3.7.3/2):对于特定于类的
operator new
或operator delete
,运算符重载。For the global
operator new
andoperator delete
, it's actually neither overloading nor overriding. A program is permitted to replace the default, implementation-provided definitions with its own definitions. The C++ standard says (§3.7.3/2):For a class-specific
operator new
oroperator delete
, the operators are overloaded.