Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

new/delete "override" vs. "overload"

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

like image 454
spc-mrn Avatar asked Sep 18 '10 17:09

spc-mrn


1 Answers

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.

like image 94
James McNellis Avatar answered Oct 03 '22 08:10

James McNellis