我是 C++ 新手,发现它对 stl 容器上的处理指针感到困惑。stl容器如何处理指针?
Point *p1 = new Point(10, 10);
std::vector<Point*> points;
points.push_back(p1);
delete p1; // or delete points[0]
std::cout << points[0]->getID() << "\n"; //why does this still display 10, 10 after deleting above?
std::cout << p1->getID(); //ofcourse, this one will output garbage
//getID method displays xy coordinates given as parameters when object is created
//The result displayed
10, 10
-1, 12337