Why is this an issue?
The delete
operator expects a pointer argument. Passing it an object may compile and seem to run (with an implicit cast to pointer
type) but it can result in unexpected behavior at runtime.
Noncompliant code example
class CString {
public:
operator const char*();
// ...
};
void fun() {
CString str;
// ...
delete str; // Noncompliant
}
Compliant solution
void fun() {
CString *pstr = new CString;
// ...
delete pstr;
}