I am new to C++, and confused about how does a class access a public method in another class in C++. For example,
//.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->setDimension(int width, int height);
}
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 setDimension was not declared in this scope
. How can I call the setDimension method inside class B. Many thanks!