質問

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?

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top