Why am I getting a g++ error about discarding qualifiers in my code when compiling?
<p>Just a little warning: I've only been doing C++ for 2 weeks now, expect to see stupid beginner errors.</p>

<p>I was writing some (useless) code to get familiar with classes in C++ (it's a wrapper around a string), and I added a copy constructor, but I keep on getting this error:</p>

<pre><code>pelsen@remus:~/Dropbox/Code/C++/class-exploration&gt; make val
g++ -o val.o val.cpp
val.cpp: In copy constructor ‘CValue::CValue(const CValue&amp;)’:
val.cpp:27: error: passing ‘const CValue’ as ‘this’ argument of ‘const std::string CValue::getData()’ discards qualifiers
make: *** [val] Error 1
</code></pre>

<p>I have done research, apparently this error is caused by the copy constructor doing non-const operations. I get that much. In response, I made CValue::getData() a const member. Apart from accessing getData(), the copy constructor doesn't do anything, so I don't see why I am still getting the error. Here is (some of) the buggy code:</p>

<pre><code>  7 class CValue {
  8   string *value;
  9 public:
 10   CValue();
 11   CValue(string);
 12   CValue(const CValue&amp; other);
 13   ~CValue();
 14   void setData(string);
 15   const string getData();
 16 };
 17 
 22 CValue::CValue(string data) {
 23   value = new string(data);
 24 }
 25 
 26 CValue::CValue(const CValue&amp; other) {
 27   value = new string(other.getData());
 28 }
 37 
 38 const string CValue::getData() {
 39   return(*value);
 40 }
</code></pre>

<p>Does anyone know what I'm doing wrong? Cause I have no idea. Thanks in advance, and I guess I'm buying a proper C++ book to get started properly. </p>
