title: C++ - Private variables in classes
body: <p>I am trying to create a class in seperate files with private variables.
  So far my classes code is:</p>
  
  <p>In TestClass.h</p>
  
  <pre><code>#ifndef TESTCLASS_H
  #define TESTCLASS_H
  #include &lt;string&gt;
  using namespace std;
  
  class TestClass
  {
      private:
          string hi;
      public:
          TestClass(string x);
          void set(string x);
          void print(int x);
  };
  
  #endif
  </code></pre>
  
  <p>In TestClass.cpp</p>
  
  <pre><code>#include "TestClass.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  TestClass::TestClass(string x)
  {
      cout &lt;&lt; "constuct " &lt;&lt; x &lt;&lt; endl;
  }
  
  void set(string x){
      hi = x;
  }
  
  void print(int x){
      if(x == 2)
          cout &lt;&lt; hi &lt;&lt; " x = two\n";
      else if(x &lt; -10)
          cout &lt;&lt; hi &lt;&lt; " x &lt; -10\n";
      else if(x &gt;= 10)
          cout &lt;&lt; hi &lt;&lt; " x &gt;= 10\n";
      else
          cout &lt;&lt; hi &lt;&lt; " x = " &lt;&lt; x &lt;&lt; endl;
  }
  </code></pre>
  
  <p>When I try to build in Code::Blocks it says:</p>
  
  <ul>
  <li>...\TestClass.cpp: In function 'void set(std::string)':</li>
  <li>...\TestClass.cpp:12: error: 'hi' was not declared in this scope</li>
  <li>...\TestClass.cpp: In function 'void print(int)':</li>
  <li>...\TestClass.cpp:17: error: 'hi' was not declared in this scope</li>
  <li>...\TestClass.cpp:19: error: 'hi' was not declared in this scope</li>
  <li>...\TestClass.cpp:21: error: 'hi' was not declared in this scope</li>
  <li>...\TestClass.cpp:23: error: 'hi' was not declared in this scope</li>
  </ul>
  
  <p>But when I run it (and don't build it) everything is working. </p>