Friend Class


Is it possible to access the private or public variables of a class within another class using friend class.If so, how?
I am a beginner at c++ programming, so any help would be welcome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class person
{
  private:
     int age;
     int height;

    friend class consultant;
};

class consultant
{
  private: 
      Person aPerson;

     cout<<"how old are you";
     cout<<aPerson.age;   
   //consultant has permision to access private data of person since they are friends
     
    cout<<"how told are you?";
    cout<<aPerson.height;
};

Thanks a lot !!!
Topic archived. No new replies allowed.