Does a class have access to protected fields of another, aggregated class during aggregation?

 class Date { protected: int year; int month; int day; }; class Application { Date* date; string FinalPoint; int destination; }; 

    2 answers 2

     class Date { friend class Application; protected: int year; int month; int day; }; 

    So the Application class will get access to all fields of the Data class object. Any object, not only aggregated ...

    • Thanks Harry :)))) worked)) - Maryna Said
    • one
      Where did it go somewhere ... :) - Harry

    Not. Direct access to protected fields is possible only through inheritance. (If you do not consider "friends", etc.)

    • I added sample code to the question. The compiler throws an error because the Date fields are closed. Is it really possible to do something like this so that Application gets access to Date? - Maryna Said
    • @Maryna Said: Unreal, unless you make Application "friend" of Date . - AnT
    • Can you please tell me how to make classes friends? - Maryna Said