[英]Problems creating a buffer in C++
我創建了這樣的緩沖區結構:
template <typename T>
class locked_buffer {
public:
locked_buffer(int n);
locked_buffer(const locked_buffer &) = delete;
~locked_buffer() = default;
int size() const noexcept;
bool empty() const noexcept;
bool full() const noexcept;
void put(const T & x, bool last) noexcept;
std::pair<bool,T> get() noexcept;
private:
int next_position(int p) const noexcept;
bool do_empty() const noexcept;
bool do_full() const noexcept;
private:
struct item {
bool last;
T value;
};
const int size_;
std::unique_ptr<item[]> buf_;
int next_read_ = 0;
int next_write_ = 0;
mutable std::mutex mut_;
std::condition_variable not_full_;
std::condition_variable not_empty_;
};
template <typename T>
locked_buffer<T>::locked_buffer(int n) :
size_{n},
buf_{new item[size_]}
{
}
template <typename T>
int locked_buffer<T>::size() const noexcept
{
return size_;
}
但是當我嘗試在主要功能中使用它時,
locked_buffer <std::pair<int, std::vector<std::vector<unsigned char>>>> buffer1;
我收到這樣的錯誤:
error: missing template arguments before ‘std’ locked_buffer <std::pair<int, std::vector<std::vector<unsigned char>>>>buffer1;
我想可能是我沒有正確創建模板,但是由於無法找到合適的解決方案,我感到非常沮喪。
謝謝。
正如@TomaszPlaskota所說的,我創建了一個具有n個元素的類型為locked_buffer
的對象,其中“ n”代表我正在創建的緩沖區的大小。
locked_buffer <std::pair<int, std::vector<std::vector<unsigned char>>>> buffer1(n);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.