将方法放入C 中的缓冲液中
Put method into a buffer in C++
我创建了此方法将一些数据放在缓冲区中:
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
- 您的1 st 参数是类型:
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
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 使用std::函数映射对象方法
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- C++从另一个类访问公共静态向量的正确方法是什么
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 是否有一种缓冲方法进行同步
- 将方法放入C 中的缓冲液中
- 在网络应用程序中缓冲数据的OOP方法
- OpenGL:从许多帧缓冲纹理中读取空间像素数据的有效方法
- c++有效的缓冲文本和有条件地将部分写入文本文件的方法