当前位置:网站首页>Differences between standard library functions and operators

Differences between standard library functions and operators

2022-07-06 00:49:00 qq_ one billion four hundred and ten million eight hundred and

Reprint : The difference between standard library functions and operators _farmwang The column -CSDN Blog _ The difference between operators and library functions

malloc/free Why new/delete?

【 answer 】

malloc And free yes C++/C Standard library functions for languages ,new/delete yes C++ Operator . They can be used to request dynamic memory and free memory . For objects that are not internal data types , Light use maloc/free Can't meet the requirements of dynamic objects . Object to be created at the same time to automatically execute the constructor , Objects are automatically destructed before they die . because malloc/free It's a library function, not an operator , Not in compiler control , The task of executing constructors and destructors cannot be imposed malloc/free. therefore C++ Language needs an operator that can accomplish dynamic memory allocation and initialization new, And an operator to clean up and free memory delete. Be careful new/delete It's not a library function .

a key :

1. Library function is that you must have this library to call this function

2.new/delete It's the operator , So you can set the new and delete Rewrite , and malloc/free No way.

 

原网站

版权声明
本文为[qq_ one billion four hundred and ten million eight hundred and ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140210469432.html