What happens when you deallocate a pointer twice or more in C++?

前端 未结 7 2256
自闭症患者
自闭症患者 2020-11-28 09:12
int main() {
    Employee *e = new Employee();

    delete e;
    delete e;
    ...
    delete e;
    return 0;
}
相关标签:
7条回答
  • 2020-11-28 10:11

    Aside from the old saw about "undefined behavior" meaning anything could happen from nothing to a gateway to the seventh circle of the inferno opening up in main memory, in practice what will usually happen in most implementations is that the program will continue to run past the deletes, and then mysteriously crash sometime later in some unrelated memory allocation.

    0 讨论(0)
提交回复
热议问题