title: Operator = Overload with Const Variable in C++
body: <p>I was wondering if you guys could help me. </p>
  
  <p>Here are my .h:</p>
  
  <pre><code>Class Doctor {
     const string name;
     public:
         Doctor();
         Doctor(string name);
         Doctor &amp; Doctor::operator=(const Doctor &amp;doc);
  }
  </code></pre>
  
  <p>and my main:</p>
  
  <pre><code>int main(){
      Doctor d1 = Doctor("peter");
      Doctor d2 = Doctor();
      d2 = d1;
  }
  </code></pre>
  
  <p>I want to do the operator= function. Can anyone help me? Notice the const member on Doctor.</p>
  
  <p>************EDIT:*********
  My main problem is that I want another class to have an attribute which is a Doctor like a Pacient has a Doctor. But I want to be able to change my Doctor. Like i am seeing doctor A but I want to see Doctor B. That would be done using a setDoctor function in my other class (Pacient). If it was me doing the code I would say something like this:</p>
  
  <pre><code>class Patient{
      Doctor &amp;d;
  };
  </code></pre>
  
  <p>and then change the pointer. However I am using a base code made by one of the teachers and it has the class defined like:</p>
  
  <pre><code>class Patient{
       Doctor d;
  }
  </code></pre>
  
  <p>But I think this is impossible to do because with a setDoctor() in the Patient class I would either make a copy or alter the varable itself. The first doesn't make any difference and the second is impossible due to the const. Am I right?</p>