In C++11 N3485 5.3.5.1 it says:
The operand [of
delete
] shall be a pointer to object type or a class type. If of class type, the operand is contextually converted to a pointer to object type.
What is an example of such usage (operand is of class type)?
If of class type, the operand is contextually implicitly converted to a pointer to object type.
So, you can use delete
on object, but when and only when this type has implicit conversion operator to pointer.
class A
{
public:
class Inner {};
A()
{
inner = new Inner();
}
operator Inner*() { return inner; }
private:
Inner* inner;
};
int main()
{
A* a = new A();
delete *a;
delete a;
}
However, it's not new feature of C++11, in C++03 standard there are almost same words
The operand shall have a pointer type, or a class type having a single conversion function (12.3.2) to a pointer type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With