0
Accessing one class to another class using pointer?
Can a class use a vector pointer as a gateway to accessing another class? Or can classes interact with each other in any way through pointers?
2 Réponses
+ 8
classes interact with each other by using pointers like this
you can pass a reference to the Manager in the constructor of OtherClass, store it in a private variable, and access _bc through it, like this:
class OtherClass {
Manager &_m;
public:
OtherClass(Manager &m) : _m(m) {}
void print(){
cout << _m._bc[0]->getNum() << " " << _m._bc[1]->getNum() << endl; } };
This is only one way to solve the problem of scope; other ways include passing Manager as a parameter of OtherClass::print, making _m a pointer, making _bc static, and so on. The exact way depends on your requirements
0
yes it can