R.15: Always overload matched allocation/deallocation pairs
R.15: 應該成對重載分配和釋放函數
Reason(原因)
Otherwise you get mismatched operations and chaos.
要不然的話就會發生不匹配的操作和混亂。
Example(示例)
<code>class X {
// ...
void* operator new(size_t s);
void operator delete(void*);
// ...
};/<code>
Note(注意)
If you want memory that cannot be deallocated, =delete the deallocation operation. Don't leave it undeclared.
如果你需要不會被釋放的內存,使用=delete禁止釋放操作。不要放任它不被定義。
Enforcement(實施建議)
Flag incomplete pairs.
標記沒有成對重載的操作。
原文鏈接:
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r15-always-overload-matched-allocationdeallocation-pairs
覺得本文有幫助?請分享給更多人。
關注【面向對象思考】輕鬆學習每一天!
面向對象開發,面向對象思考!
閱讀更多 面向對象思考 的文章