【发布时间】:2018-03-05 09:41:01
【问题描述】:
我有以下代码:
unsigned char* frame_buffer_data{ new unsigned char[data_size] };
glReadPixels(origin_x, origin_y, width, height, GL_BGR, GL_UNSIGNED_BYTE, frame_buffer_data);
我想摆脱原始指针 (frame_buffer_data) 并使用唯一指针。
试试这个:
std::unique_ptr<unsigned char> framebuffer_data(new unsigned char[data_size] );
不工作。
如何将唯一指针(或其他智能指针)传递给此函数?
在调用glReadPixels 之后,我需要能够reinterpret cast 数据类型并将数据写入文件,如下所示:
screenshot.write(reinterpret_cast<char*>(frame_buffer_data), data_size);
【问题讨论】:
-
不工作怎么办?你得到一个编译错误?哪个错误?
-
我会先看
std::vector,而不是智能指针。此外,这将调用错误版本的delete。
标签: c++ smart-pointers