开发者

new/delete "override" vs. "overload"

I always thought...

  • overriding means reimplementing a function (sa开发者_StackOverflow中文版me 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"...


For the global operator new and operator 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):

The library provides default definitions for the global allocation and deallocation functions. Some global allocation and deallocation functions are replaceable (18.4.1). A C++ program shall provide at most one definition of a replaceable allocation or deallocation function. Any such function definition replaces the default version provided in the library (17.4.3.4).

For a class-specific operator new or operator delete, the operators are overloaded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜