【发布时间】:2016-01-12 21:35:06
【问题描述】:
我是否只能在使用 new 时删除指针? 我试过这样的代码:
std::vector<float>* intersections;
intersections=&KIN_Trigonometry::getIntersectionCircleAndLine( xA, yA, xB, yB, x, y, radius * 2, nbPoints);
delete intersections;
它给我断言失败...... 我在使用 new like 时已经使用了带指针的 delete
int* p = new int[2];
delete p;
感谢您的支持
【问题讨论】:
-
要么
getIntersectionCircleAndLine返回对成员变量的引用(在堆栈上,最有可能的选项),要么分配内存,返回指向它的指针,但决定管理内存(即调用delete[]) 之后。无论哪种方式,都会发生双重删除,您可能不应该这样做 -
谢谢你!我也是这么想的,我不明白为什么我的话题投了反对票……
-
你能显示 KIN_Trigonometry::getIntersectionCircleAndLine 函数的签名吗?
-
静态 std::vector
getIntersectionCircleAndLine(float xl, float yl, float xl2, float yl2, float xC, float yC, float r, int circlesPoints); -
@sachaamm,它没有编译,你是怎么编译的? my code
标签: c++ pointers new-operator delete-operator assertion