Domanda

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?

È stato utile?

Soluzione

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top