1

I accidentally called operator delete[] on a ifstream object, instead of on a file name. I expected the compiler to issue an error because delete[] only operates on pointers, not objects. However, the compiler didn't complain (not even a warning).

When debugging this, I saw that the system calls operator void* on the object. Surprisingly, this doesn't even crash (demo).

So I wonder: why does this operator exists in first place?

Is it needed to support the if (!file) syntax? If yes, why not convert it to a safe-bool or use an explicit operator bool instead?

anatolyg
  • 26,506
  • 9
  • 60
  • 134

0 Answers0