Overloading operator new for a class

后端 未结 1 809
暖寄归人
暖寄归人 2020-12-08 16:04

When we overload new operator of a class, we declare the function as a member function. For eg:

class OpNew {
public:
    OpNew() { cout << \"OpNew::Op         


        
相关标签:
1条回答
  • 2020-12-08 16:21

    An operator new() or operator new[]() for a class is always a static class member, even if it is not declared with the keyword static.

    What the C++ standard says (draft n3242), in section [class.free]:

    Any allocation function for a class T is a static member (even if not explicitly declared static).

    0 讨论(0)
提交回复
热议问题