title: How to use a std::lock_guard without violating const correctness?
body: <p>In a subclass, I have a private <code>std::mutex m</code> field that I use in an implementation of a base class pure virtual method to return a value in a thread-safe way (the value can be updated by another thread):</p>
  
  <pre><code>int SubClass::get() const // implements 'virtual int get() = 0 const' of the base class
  {            
      std::lock_guard&lt;std::mutex&gt; lck(m); 
      return value;
  }
  </code></pre>
  
  <p>The compiler is telling me that this violates const correctness by producing an error:</p>
  
  <blockquote>
    <p>error: binding 'const std::mutex' to reference of type
    'std::lock_guard::mutex_type&amp; {aka std::mutex&amp;}' discards
    qualifiers</p>
  </blockquote>
  
  <p>Is there a way to make this compliant and use <code>std::lock_guard</code> in a const-correct way? Simply changing it to <code>const std::lock_guard</code> changes nothing. I don't really understand which part is problematic, then again I'm quite new to C++ ...</p>