将内存分配给 std::array 时出错
Error with assigning memory to std::array
我的目的是将队列中的图像缓冲区传递给其他函数(在另一个线程中)进行处理,使用 http://www.cplusplus.com/reference/array/array/data/ 中的示例。但是我收到以下错误:
error: request for member ‘data’ in ‘frame’, which is of non-class type ‘std::array<unsigned char, 345600>()’
和
error: no matching function for call to ‘std::deque<std::array<unsigned char, 345600> >::push_back(std::array<unsigned char, 345600> (&)())’
这是我的代码,我想知道错误在哪里
// Declaration of array
std::deque<std::array<unsigned char, FRAME_WIDTH * FRAME_HEIGHT>> frameQueue;
// some processing
// some processing take place and the output is some buffer buf , type unsigned char
// declare an array object
std::array<unsigned char, FRAME_HEIGHT * FRAME_WIDTH> frame();
// set the array with memory from buf
std::memcpy (frame.data(), buf, FRAME_HEIGHT * FRAME_WIDTH);
// push it into queue
frameQueue.push_back(frame);
谢谢
我认为你不应该在这一行的框架前面使用括号:
std::array frame();
正确的命令是:
std::array<无符号字符,FRAME_HEIGHT * FRAME_WIDTH> 框架;
我的目的是将队列中的图像缓冲区传递给其他函数(在另一个线程中)进行处理,使用 http://www.cplusplus.com/reference/array/array/data/ 中的示例。但是我收到以下错误:
error: request for member ‘data’ in ‘frame’, which is of non-class type ‘std::array<unsigned char, 345600>()’
和
error: no matching function for call to ‘std::deque<std::array<unsigned char, 345600> >::push_back(std::array<unsigned char, 345600> (&)())’
这是我的代码,我想知道错误在哪里
// Declaration of array
std::deque<std::array<unsigned char, FRAME_WIDTH * FRAME_HEIGHT>> frameQueue;
// some processing
// some processing take place and the output is some buffer buf , type unsigned char
// declare an array object
std::array<unsigned char, FRAME_HEIGHT * FRAME_WIDTH> frame();
// set the array with memory from buf
std::memcpy (frame.data(), buf, FRAME_HEIGHT * FRAME_WIDTH);
// push it into queue
frameQueue.push_back(frame);
谢谢
我认为你不应该在这一行的框架前面使用括号:
std::array
正确的命令是:
std::array<无符号字符,FRAME_HEIGHT * FRAME_WIDTH> 框架;