Question

I would like to take the address of operator (std::nothrow) new.

typedef void* (*NewFunc)(size_t);
NewFunc newAddr = &operator new; // OK

typedef void* (*NewFuncNoThrow)(size_t, const std::nothrow_t&);
NewFuncNoThrow newAddrNoThrow = &operator (std::nothrow) new; // Syntax error ')'

What should be the right syntax for my last line above?

Was it helpful?

Solution

The same as the previous one:

NewFuncNoThrow newAddrNoThrow = &operator new;

operator new is an overloaded function name. It will be resolved when needed to convert to a specific type - and that type is NewFuncNoThrow, which will guide it to the correct overload.

Live example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top