I was wondering how you would call a getter function from another class in another class. For example what I have right now is not working
class A{
public:
friend class B;
std::string getfirst(){ return b.getfirst();}
private:
B b;
};
class B{
public:
std::string getfirst(){
return first_;
}
private:
std::string first_;
};
How would I fix this so that I can call B’s getfirst function?
You do not need friendship.
What about?
Now, class B has a getter for its first and class A has getter that delegates to b member variable.