0

I have created this method to put some data in a buffer:

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();
}

But, trying to put data which consists in a return of a function:

int size_b;
locked_buffer<long buf1{size_b}>;
buf1.put(image, true); //image is the return of the function

I've got problems with the boolean variable bool lastbecause I've got compilation errors.

Thanks.

Edit: The error that I obtained is the following one:

error: no matching function for call to 'locked_buffer<long int>::put(std::vector<std::vector<unsigned char>>&, bool)'
giorgioW
  • 331
  • 5
  • 20
  • 4
    Provide a [MCVE] including the verbatim error messages please. – πάντα ῥεῖ Dec 09 '16 at 13:41
  • I can only guess: locked_buffer – Jürgen Schwietering Dec 09 '16 at 13:42
  • 1
    What exactly is the compilation error you're getting? – AresCaelum Dec 09 '16 at 13:46
  • 1
    Typo ? should it be `locked_buffer buf1{size_b};` ? – Jarod42 Dec 09 '16 at 13:47
  • ok... so is it locked_buffer or locked_buffer buf1{size_b}? I dont even know if the first option is even valid code to be honest. But regardless your compiler error says you are using 2 different data types for your template class, you are creating the class to expect a long int type for T and then you are passing a different type to the method, the type to the method needs to be the same type that is used to create your object. – AresCaelum Dec 09 '16 at 13:59

1 Answers1

2

error: no matching function for call to locked_buffer<long int>::put(std::vector<std::vector<unsigned char>>&, bool)

Tells you everything you need to know:

  1. Your locked_buffer object is templated to type: long int
  2. Your 1st argument is of type: vector<vector<unsigned char>>

Now we know that these 2 types must be the same from your function definition:

template <typename T>
void locked_buffer<T>::put(const T & x, bool last) noexcept

The compiler's error is correct. You'll need to either use a matching locked_buffer object or create a new function:

template <typename T, typename R>
void locked_buffer<T>::put(const R& x, bool last) noexcept
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288