title: Why copy constructor, operator= and reference in this class have compile issue
body: <p>I tried to search for solution but found nothing. If this is a duplicated question, I apologize in advance.</p>
  
  <p>I have a class like this:</p>
  
  <pre><code>class sync_lock {
      public:
          enum lock_status { free, locked };
          pthread_cond_t cond;
          pthread_mutex_t mtx;
          lock_status status;
  
          sync_lock() : status(free) {
              pthread_cond_init( &amp;cond, NULL );
              pthread_mutex_init( &amp;mtx, NULL );
          }
  
          sync_lock(const sync_lock &amp; param) {
              cond = param.cond;
              mtx = param.mtx;
              status = param.status;
          }
  
          sync_lock &amp; operator=(const sync_lock &amp; param) {
              if (this == &amp;param)
                  return *this;
              cond = param.cond;
              mtx = param.mtx;
              status = param.status;
              return *this;
          }
  
          ~sync_lock() {
              pthread_cond_destroy( &amp;cond );
              pthread_mutex_destroy( &amp;mtx );
          }
  };
  </code></pre>
  
  <p>And in the driver code, I have this:</p>
  
  <pre><code>line 29: sync_lock lock();
  line 30: lock_map[lid] = lock;
  </code></pre>
  
  <p>Another place has this:</p>
  
  <pre><code>line 33: sync_lock &amp; lock = lock_map[lid];
  </code></pre>
  
  <p>When I compile, I got this:</p>
  
  <pre><code>lock_server.cc: In member function ‘lock_protocol::status lock_server::acquire(int, lock_protocol::lockid_t, int&amp;)’:
  lock_server.cc:30:25: error: no match for ‘operator=’ in ‘((lock_server*)this)-&gt;lock_server::lock_map.std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[] [with _Key = long long unsigned int, _Tp = sync_lock, _Compare = std::less&lt;long long unsigned int&gt;, _Alloc = std::allocator&lt;std::pair&lt;const long long unsigned int, sync_lock&gt; &gt;, std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::mapped_type = sync_lock, std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::key_type = long long unsigned int]((*(const key_type*)(&amp; lid))) = lock’
  lock_server.cc:30:25: note: candidate is:
  lock_server.h:33:21: note: sync_lock&amp; sync_lock::operator=(const sync_lock&amp;)
  lock_server.h:33:21: note:   no known conversion for argument 1 from ‘sync_lock()’ to ‘const sync_lock&amp;’
  make: *** [lock_server.o] Error 1
  </code></pre>
  
  <p>I have no idea what caused this error. Any thoughts? Thanks in advance!</p>