开发者

operator new and new operator, which can't be overloaded?

开发者 https://www.devze.com 2022-12-23 07:58 出处:网络
It seems both can be overloaded, bu开发者_运维百科t somebody said not..... What\'s the case?It seems you are making the distinction between the handling of new-expressions and allocation functions. n

It seems both can be overloaded, bu开发者_运维百科t somebody said not.....

What's the case?


It seems you are making the distinction between the handling of new-expressions and allocation functions. new-expressions call constructors in addition for class types and is responsible for looking up allocation functions (so it is built into the compiler) and calling them. You can't change that behavior. What you can change is the behavior of allocation functions. Their name is operator new and they are found and used by new-expressions to allocate memory.

See Plain new, new[], delete and delete[] in a nutshell.


You can overload all four of, new, new[], delete, and delete[]. See section 13.5 of the standard.


You can overlload new operator but you cannot define new operators(like ^ or ++).

If it is not what you meant please clarify.

0

精彩评论

暂无评论...
验证码 换一张
取 消