title: Undeclared indentifier compile error
body: <p>I am throwing myself in the cold blizzard of learning C++. I already know Java but C++ seems odd on certain thing.</p>
  
  <p>Here is the thing : I have a class A and a class B. Class A have an instance of class B inside of itself. Class B needs to be able to call some class A methods so, I put a pointer to class A inside class B's constructor, and store it inside a variable so I can retrieve these methods with this variable.</p>
  
  <p>Here is my code (simplified) :</p>
  
  <h3>ClassA.h</h3>
  
  <pre><code>#ifndef CLASSA
  #define CLASSA
  
  #include "ParentClass.h"
  #include "ClassB.h"
  
  class ClassA : public ParentClass {
  
  private:
  ClassB *classB;
  
  public:
  ClassA(void);
  virtual ~ClassA(void);
  
  };
  #endif
  </code></pre>
  
  <h3>ClassA.cpp</h3>
  
  <pre><code>   #include "ClassA.h"
  
     //-----------------------------------------------------
     ClassA::ClassA(void){
      classB= new ClassB(this);
     }
     //-----------------------------------------------------
     ClassA::~ClassA(void)
     {
     }
     //-----------------------------------------------------
  </code></pre>
  
  <h3>ClassB.h</h3>
  
  <pre><code>#ifndef CLASSB
  #define CLASSB
  
  #include "ClassA.h"
  
  class ClassB{
  
  public:
  ClassB(ClassA &amp;pClassA){ classA = pClassA; };
  ClassA *getClassAInstance(){ return classA; };
  
  private:
  ClassA *classA;
  };
  #endif
  </code></pre>
  
  <h3>ClassB.cpp</h3>
  
  <pre><code>#include "ClassA.h"
  
  /*ClassB::ClassB(void){
  classA= pClassA;
  }*/
  </code></pre>
  
  <p>Visual Express doesn't give errors but when I compile, it says that class B doesn't recognize what is a class A. What the hell ?</p>
  
  <blockquote>
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2061: syntax
    error : identifier 'ClassA'</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C2143: syntax
    error : missing ';' before '*'</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C4430:
    missing type specifier - int assumed. Note: C++ does not support
    default-int</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C4430:
    missing type specifier - int assumed. Note: C++ does not support
    default-int</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): warning C4183:
    'getClassAInstance': missing return type; assumed to be a member
    function returning 'int'</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C2143: syntax
    error : missing ';' before '*'</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C4430:
    missing type specifier - int assumed. Note: C++ does not support
    default-int</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(13): error C4430:
    missing type specifier - int assumed. Note: C++ does not support
    default-int</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2065:
    'classA' : undeclared identifier</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(8): error C2065:
    'pClassA' : undeclared identifier</p>
    
    <p>1>c:\xxx\xxx\xxx\xxx\xxx\xxx\xxx\xxx\ClassB.h(10): error C2065:
    'classA' : undeclared identifier</p>
  </blockquote>
  
  <p>Undeclared what ? Returning int ?</p>
  
  <blockquote>
    <p>undeclared identifier</p>
  </blockquote>
  
  <p>Why? I included everything, right ? Any ideas what is wrong, guys ?</p>