小编lun*_*ies的帖子

C++使用*新类,丢失指针?

好奇为什么会失败.在返回对象而不是指针本身使用new的情况下,为什么在之后制作指针然后删除指针是非法的.我是否误解了这个序列的某些内容?

例如

Example e = *new Example();      //dereferencing the pointer to get Example object
Example* g = &e;                 //pointer pointing to e's address
delete g;                        //g is still pointer, but errors here.
Run Code Online (Sandbox Code Playgroud)

c++ pointers

3
推荐指数
1
解决办法
136
查看次数

标签 统计

c++ ×1

pointers ×1