title: error: function was not declared in this scope
body: <p>I have to carry out this simple exercise: I have a buffer and I have to insert into this buffer the data taken from an input_file.txt file, for example this:</p>
  <pre><code>1
  2
  3
  4
  </code></pre>
  <p>Then these data are read and inserted into the buffer with the <code>read_position</code> function, and then they are read and written to the terminal with the <code>write_position</code> function. Also, I have to manage access to the buffer.
  This is the buffer.h:</p>
  <pre><code>// Buffer.h
  
  #ifndef Buffer_h
  #define Buffer_h
  
  #include &lt;queue&gt;
  using std::queue;
  #include &lt;mutex&gt;
  using std::mutex;
  #include &lt;condition_variable&gt;
  using std::condition_variable;
  
  class Buffer
  {
      public:
          void append(double v);
          double take();
  
      private:
          queue&lt;double&gt; buffer_;
          mutex mutex_;
          condition_variable not_empty_;       
  };
  
  #endif
  </code></pre>
  <p>this is buffer.cpp:</p>
  <pre><code>//Buffer.cpp
  #include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  #include &lt;fstream&gt;
  using std::ifstream;
  #include &lt;string&gt;
  using std::string;
  #include &lt;mutex&gt;
  using std::mutex;
  using std::unique_lock;
  #include &lt;condition_variable&gt;
  using std::condition_variable;
  
  #include &quot;Buffer.h&quot;
  
  void Buffer::append(double shift)
  {
      unique_lock&lt;mutex&gt; mlock(mutex_);
      buffer_.push(shift);
      not_empty_.notify_one(); //signalC
  }
  
  double Buffer::take()
  {
      unique_lock&lt;mutex&gt; mlock(mutex_);
      while(buffer_.empty())
          not_empty_.wait(mlock); //waitC
      double posit =buffer_.front();
      buffer_.pop();
      return posit;
  }
  
  void read_position(Buffer buf)
  {
      ifstream input(&quot;input_file.txt&quot;);
          if(!input.is_open())
      {
          cout &lt;&lt; &quot;Unable to open the input file.&quot; &lt;&lt; endl;
          exit(EXIT_FAILURE);
      }
     string line;
     while (getline (input, line)){
          size_t pos = line.find_first_of(&quot; &quot;,0);
          double position = stod(line.substr(pos+1,line.size()));
          buf.append(position);
      }
  }
  
  void write_position(Buffer buf)
  {
      for(int i=0; i&lt;4; i++){
              double pos= buf.take();
              cout&lt;&lt;pos&lt;&lt;endl;
      }
  }
  </code></pre>
  <p>This is main:</p>
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  #include &lt;thread&gt;
  using std::thread;
  
  
  #include &quot;Buffer.h&quot;
  
  Buffer b1;
  
  int main(int argc, char* argv[])
  {
      thread read{read_position, b1};
      thread write{write_position, b1};
  
      read.join();
      write.join();
     
      cout &lt;&lt; &quot;End of main thread.&quot; &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>
  <p>When I compile I get this error:</p>
  <pre><code>main.cpp: In function ‘int main(int, char**)’:
  main.cpp:35:17: error: ‘read_position’ was not declared in this scope
     35 |     thread read{read_position, b1};
        |                 ^~~~~~~~~~~~~
  main.cpp:35:34: error: no matching function for call to ‘std::thread::thread(&lt;brace-enclosed initializer list&gt;)’
     35 |     thread read{read_position, b1};
        |                                  ^
  In file included from main.cpp:4:
  /usr/include/c++/9/thread:144:5: note: candidate: ‘std::thread::thread(std::thread&amp;&amp;)’
    144 |     thread(thread&amp;&amp; __t) noexcept
        |     ^~~~~~
  /usr/include/c++/9/thread:144:5: note:   candidate expects 1 argument, 2 provided
  /usr/include/c++/9/thread:117:7: note: candidate: ‘template&lt;class _Callable, class ... _Args, class&gt; std::thread::thread(_Callable&amp;&amp;, _Args&amp;&amp; ...)’
    117 |       thread(_Callable&amp;&amp; __f, _Args&amp;&amp;... __args)
        |       ^~~~~~
  /usr/include/c++/9/thread:117:7: note:   template argument deduction/substitution failed:
  /usr/include/c++/9/thread:112:5: note: candidate: ‘std::thread::thread()’
    112 |     thread() noexcept = default;
        |     ^~~~~~
  </code></pre>