delete 对象后调用该对象的方法程序不报错 博客分类: c++
程序员文章站
2024-03-19 10:21:10
...
delete 一个对象后,在执行该对象的方法,并不会报错,而返回一个不确定的值。
/*测试 delete MyVector 对象后,执行 is_eof() 函数是否显示已经结束*/ #include "vector.h" using uint32 = unsigned int; int main(){ MyVector<uint32> * mv = new MyVector<uint32> (); mv->start_write(); mv->push_back(1); mv->push_back(2); mv->start_read(); while(!mv->is_eof()){ std::cout << mv->get() << " "; mv->next_remove(); } delete mv; if( mv->is_eof() )std::cout << " is_eof() is true.\n"; else std::cout << " is_eof() is false.\n"; return 0; }