title: unknown type name on defining object of another class from same file in C++
body: <p>In my one c++ file named "two_elements.cpp", I am defining two classes within same file, and the code goes like below:
  <code></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstream&gt;
  
  class A{
      public:
          void methodA(){
              //do something
          }
  };
  
  class B{
      public:
          A a_obj;
          a_obj.methodA();
  };
  </code></pre>
  
  <p></code></p>
  
  <p>This throws the following error:</p>
  
  <pre><code>error: unknown type name 'a_obj'
  </code></pre>
  
  <p>I folowed the following stack overflow links comprehensively, but could not find a work around:</p>
  
  <p><a href="https://stackoverflow.com/questions/16336244/unknown-type-name-class">Unknown type name class</a></p>
  
  <p><a href="https://stackoverflow.com/questions/40311370/unknown-type-name-class">unknown type name &#39;class&#39;</a></p>
  
  <p><a href="https://stackoverflow.com/questions/677325/c-2-classes-1-file">C++ - 2 classes 1 file</a></p>
  
  <p>Please note most of these questions had classes in the individual header files.</p>