If you don't want to use ::
, you don't really have to. In fact, you generally shouldn't (don't want to).
You can provide replacements for ::operator new
and ::operator delete
(and the array variants, though you should never use them).
You can also, however, overload operator new
and operator delete
for a class (and yes, again, you can do the array variants, but still shouldn't ever use them).
Using something like void *x = ::operator new(some_size);
forces the allocation to go directly to the global operator new
instead of using a class specific one (if it exists). Generally, of course, you want to use the class specific one if it exists (and the global one if it doesn't). That's exactly what you get from using void *x = operator new(some_size);
(i.e., no scope resolution operator).
As always, you need to ensure that your new
s and delete
s match, so you should only use ::operator delete
to delete the memory when/if you used ::operator new
to allocate it. Most of the time you shouldn't use ::
on either one.
The primary exception to that is when/if you're actually writing an operator new
and operator delete
for some class. These will typically call ::operator new
to get a big chunk of memory, then divvy that up into object-sized pieces. To allocate that big chunk of memory, it typically (always?) has to explicitly specify ::operator new
because otherwise it would end up calling itself to allocate it. Obviously, if it specifies ::operator new
when it allocates the data, it also needs to specify ::operator delete
to match.