我创建了此方法以将一些数据放入缓冲区:
template <typename T>
void locked_buffer<T>::put(const T & x, bool last) noexcept
{
using namespace std;
unique_lock<mutex> l{mut_};
not_full_.wait(l, [this] { return !do_full(); });
buf_[next_write_] = item{last,x};
next_write_ = next_position(next_write_);
l.unlock();
not_empty_.notify_one();
}
但是,尝试放入包含函数返回的数据:
int size_b;
locked_buffer<long buf1{size_b}>;
buf1.put(image, true); //image is the return of the function
我遇到布尔变量
bool last
的问题,因为我遇到了编译错误。谢谢。
编辑:
我获得的错误是以下错误:
error: no matching function for call to 'locked_buffer<long int>::put(std::vector<std::vector<unsigned char>>&, bool)'
最佳答案
错误:没有匹配的函数调用locked_buffer<long int>::put(std::vector<std::vector<unsigned char>>&, bool)
告诉您您需要了解的所有信息:
您的locked_buffer
对象被模板化以键入:long int
您的第一个参数的类型为:vector<vector<unsigned char>>
现在我们知道您的函数定义中这两种类型必须相同:
template <typename T>
void locked_buffer<T>::put(const T & x, bool last) noexcept
编译器的错误是正确的。您需要使用匹配的
locked_buffer
对象或创建一个新函数:template <typename T, typename R>
void locked_buffer<T>::put(const R& x, bool last) noexcept