我的场景如下(VC++代码):
IDirect3DSurface9 ***ppp;
IDirect3DSurface9* p;我调用了CreateOffscreenPlainSurface( , , ,&p,null),现在p将保存D3D表面的地址。所以我想把p赋值给ppp。
我就是这么做的
(*(*ppp)) = p;但是它抛出了运行时异常。我不明白为什么。有人能在这方面帮我忙吗?
发布于 2012-06-01 22:21:00
此赋值引发异常,因为您正在写入未初始化的指针所指向的地址。您需要先为指针分配内存,然后再分配给指针数组,然后才能进行分配。
ppp = new IDirect3DSurface9**[10]; // Pick the right size here
ppp[0] = new IDirect3DSurface9*[5]; // Pick the right size here, too
ppp[0][0] = p;处理完这些数组后,不要忘记对它们执行delete[]操作。
如果使用指向指针的指针不是显式要求,请考虑使用std::vector<std::vector<IDirect3DSurface9*> >。
https://stackoverflow.com/questions/10851984
复制相似问题