title: g++: const discards qualifiers
body: <p>why do I get a <code>discard qualifiers</code> error:</p>
  
  <pre><code>customExc.cpp: In member function ‘virtual const char* CustomException::what() const’:
  customExc.cpp: error: passing ‘const CustomException’ as ‘this’ argument of ‘char customException::code()’ discards qualifiers
  </code></pre>
  
  <p>on the following code example</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  
  class CustomException: public std::exception {
  
  public:
  
      virtual const char* what() const throw() {
          static std::string msg;
          msg  = "Error: ";
          msg += code();  // &lt;---------- this is the line with the compile error 
          return msg.c_str();
      }
  
      char code() { return 'F'; }
  };
  </code></pre>
  
  <p>I have searched around on SOF before regarding simular issues.</p>
  
  <p>I have already added a <code>const</code> on every possible place.</p>
  
  <p>Please enlighten me -  I don't get the point...</p>
  
  <p><strong>EDIT</strong>:
  here are the steps to reproduce on Ubuntu-Carmic-32bit (g++ v4.4.1)</p>
  
  <ol>
  <li>save example as <code>customExc.cpp</code></li>
  <li>type <code>make customExc.o</code></li>
  </ol>
  
  <p><strong>EDIT</strong>: The error is related to <code>CustomException</code>. The class <code>Foo</code> has nothing to do with it. So I have deleted it.</p>