title: How does a class access a public method in another class in C++
body: <p>I am new to C++, and confused about how does a class access a public method in another class in C++. For example, </p>
  
  <pre><code>//.h of class A
  class A {
  public:
    void setDimension (int width, int height);
    A* obj;
  }
  
  //.cpp of class A
  #include "A.h"
  void A::setDimension (int width, int height) {
      // do some stuffs here
  }
  
  //.h of class B
  #include "A.h"
  class B {
  public:
      void function ();
     //do something here
  }
  
  //.cpp of class B
  #include "A.h"
  #include "B.h"
  void B::function() {
       obj-&gt;setDimension(int width, int height);
  }
  </code></pre>
  
  <p>And now I want the class B can access  the public method "setDimension" in class A. I think the dependency files are included, but when I run the program, I got an error says that <code>setDimension was not declared in this scope</code>. How can I call the setDimension method inside class B. Many thanks!</p>