views:

124

answers:

1

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"...

+6  A: 

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.

James McNellis
So overloading and overriding are equally wrong here, which explains the 50-50 distribution in usage :-)
spc-mrn
James: While I think what your wrote is right, you can still _overload_ both global operators with ones taking additional (or different) arguments. In fact, the std lib comes with at least to overloads: one placement new and the `nothrow` variant.
sbi
@sbi: Right. Well, the global operators are overloaded, and each of the overloads can be replaced. @spc-mrn: Yes, effectively.
James McNellis