title: "undeclared identifier" is actually declared
body: <p>I've been getting error C2065s for variables that I've declared in the class header file as public data members, one int and one pointer to that int. The lines of code being flagged as erroneous are only when I use these variables in a function - within the class' constructor, they appear to get through okay.</p>
  
  <p>I'm using Visual Studio 2010 Express to write normal C++ (not Visual C++), and here's the output of the compiler's error log:</p>
  
  <pre><code>1&gt;------ Build started: Project: Project 2, Configuration: Debug Win32 ------
  1&gt;  BaseClassWithPointer.cpp
  1&gt;d:\libraries\documents\school\advanced c++\project 2\project 2\baseclasswithpointer.cpp(27): error C2065: 'q' : undeclared identifier
  1&gt;d:\libraries\documents\school\advanced c++\project 2\project 2\baseclasswithpointer.cpp(27): error C2541: 'delete' : cannot delete objects that are not pointers
  1&gt;d:\libraries\documents\school\advanced c++\project 2\project 2\baseclasswithpointer.cpp(32): error C2065: 'num' : undeclared identifier
  1&gt;d:\libraries\documents\school\advanced c++\project 2\project 2\baseclasswithpointer.cpp(33): error C2065: 'q' : undeclared identifier
  1&gt;d:\libraries\documents\school\advanced c++\project 2\project 2\baseclasswithpointer.cpp(34): error C2065: 'q' : undeclared identifier
  1&gt;  Generating Code...
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p>Finally, here're my code blocks and headers:</p>
  
  <p>BaseClassWithPointer.h</p>
  
  <pre><code>#pragma once
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class BaseClassWithPointer
  {
  public:
      int num;
      int *q;
      BaseClassWithPointer();
      BaseClassWithPointer(int value);
      BaseClassWithPointer(const BaseClassWithPointer&amp; otherObject);
      void destroyPointer();
      virtual void print();
      virtual ~BaseClassWithPointer();                                                        //Destructor is virtual so that derived classes use their own version of the destructor. ~     (2. Inheritance - base class with pointer variables – destructors.)
      const BaseClassWithPointer&amp; operator= (const BaseClassWithPointer &amp;rhs);        //Assignment operator is overloaded to avoid shallow copies of pointers. ~ (3. Inheritance     – base class with pointer variables – assignment operator overloading.)
  
  };
  </code></pre>
  
  <p>BaseClassWithPointer.cpp</p>
  
  <pre><code>#pragma once
  #include "BaseClassWithPointer.h"
  #include &lt;iostream&gt;
  
  using namespace std;
  
  BaseClassWithPointer::BaseClassWithPointer()
  {
      num = 0;
      q = &amp;num;
  }
  
  BaseClassWithPointer::BaseClassWithPointer(int value)
  {
      num = value;
      q = &amp;num;
  }
  
  BaseClassWithPointer::BaseClassWithPointer(const BaseClassWithPointer&amp; otherObject)
  {
      num = otherObject.num;
      q = &amp;num;
  }
  
  void destroyPointer()
  {
      delete q;
  }
  
  void print()
  {
      cout &lt;&lt; "Num: " &lt;&lt; num &lt;&lt; endl;
      cout &lt;&lt; "Value pointed to by q: " &lt;&lt; *q &lt;&lt; endl;
      cout &lt;&lt; "Address of q: " &lt;&lt; q &lt;&lt; endl;
  }
  
  BaseClassWithPointer::~BaseClassWithPointer()
  {
      destroyPointer();
  }
  
  const BaseClassWithPointer&amp; BaseClassWithPointer::operator=(const BaseClassWithPointer &amp;rhs)
  {
      if (this != &amp;rhs)
      {
          num = rhs.num;
          q = &amp;num;
      }
  
      return *this;
  }
  </code></pre>