What are “::operator new” and “::operator delete”?

后端 未结 4 1050
我在风中等你
我在风中等你 2020-12-18 05:01

I know new and delete are keywords.

int obj = new int;
delete obj;

int* arr = new int[1024];
delete[] arr;

4条回答
  •  囚心锁ツ
    2020-12-18 05:25

    :: tells the compiler to call the operators defined in global namespace.
    It is the fully qualified name for the global new and delete operators.

    Note that one can replace the global new and delete operators as well as overload class-specific new and delete operators. So there can be two versions of new and delete operators in an program. The fully qualified name with the scope resolution operator tells the compiler you are referring to the global version of the operators and not the class-specific ones.

提交回复
热议问题