Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个项目规范(所以我不能改变它),我在其中创建了一个函数
const mat4& GetView() const;
mat4 对象是在这个函数上创建的:
mat4* a = new mat4(); mat4 &ret = *a; return ret;
稍后我会想删除它。但是,一旦我离开了 GetView 方法,我该怎么做呢?
谢谢。
取地址:
const mat4 & x = GetView(); delete &x;
(我假设它operator&没有超载。如果是,你需要做一些更复杂的事情。)
operator&
我强烈怀疑这里只有三个合理的选择:
GetView
const mat4&
当然,在最后一点上,你真的应该在开始推动之前尽可能多地收集理由。