R.15: Always overload matched allocation/deallocation pairs
R.15: 應該成對重載分配和釋放函數
Reason(原因)
Otherwise you get mismatched operations and chaos.
要不然的話就會發生不匹配的操作和混亂。
Example(示例)
class X {
// ...
void* operator new(size_t s);
void operator delete(void*);
// ...
};
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
覺得本文有幫助?歡迎點贊並分享給更多的人。
閱讀更多更新文章。請關注微信公衆號【面向對象思考】