Freiend Class in C++

Hi welcome we are going to discuss about friend class already in previous session without discuss that what is your friend function and how to introduce a friend function to the class today we are going to discuss about friend class ok according to the previous session a friend function is a non Member function is a non Member function of a class but it is able to access the Private data of those classes where it is introduced as a friend Here The. His only the friend function can access the Private data but I want to access the whole data from another class ok I want to access the whole data of a class from another class in this situation where having only the chances that is friend classify different classes just introduced as a friend to another class whenever if class is introduced as a friend to another class now this class is able to access all the private members of that class and here in this situation the introduced class is called the integrated classes called container class and the declared class where we have declared the front glass is called container glass OK Here were having container class and as well as container glass container class which is existing class means which is the primary class whenever this class is introduced as a friend to another class that class is called container class and this relationship is called display strip is called Commission ok that’s why here I am going to explain what is friend function and what his friend class first of all I am going to give one example on friend class how to introduce one friend class first term for example general header files hash include iostream Dart hash and hashinclude sun conure that has ok and here one more thing is we can declare friend class in two different ways one is directly declaring the French class in one class and accessing another class second one is by declaring the object of one class in another class we can access the private members now I will show you the both methods first how to introduce the friend class suppose there is a class called test one ok hear some data members Like A and B are Private data members and as per C plus plus Data Hiding concept Private data should not be available outside the class OK Here private it is not available outside the class then how to access the Private data means we should how to declare public Member function that’s why hair in public area ok general we are going to write some functions. I want to access this data through friend function or friend class that’s why what I have to do if I have to declare a friend class inside this class ok the miss I want the access Private data from another class but actually the rule is what the Private data should be accessed within the class only but I want to access this Private data from another class for this we should have to declare another class as a friend to this class that’s why dear friend which class for example Test 2 friend class test to hear what it was one is what the first class ok and here it is having the Private data now I want to access this Private data from text to class for this first of all I have to introduce the test 2 Class as a friend now ok both are friends here it get a b suppose it is a Member function to access the a b values OK Here I want to enter some data out and a b values next c in a how the function of close clash of software and here watch this test one is the class A B are the private number on to access Private data how is a Member function called get KV through the Getaway I am reading the values for and but there is no put function now I want to print this a b values from test to class + Y first of all I have to define the class test to next here there is no data requirement why because already we’re having the data in test 1 class I want to access a b from test to know if there is no need of any data directly I am going to oblique section next I want to access this data through text to function that’s why but composition allows only the usability it is the difference between inheritance and composition ok and to achieve this one we should how to declare this class as a friend to this class ok I hear one function called kutte be here the point is is the number of test to ok KV is the number of test to earn through the foot KV function I want to access the AV of test 1 that’s why hair in blackheads you should have to send object as argument because of the private data is not available outside the class ok the rule is what Private data should not be visible Private data is not visible outside the class then how it is possible means only through the class type parameters class type parameter is called what object that’s why I hear test 1 t 1 t 1 is the object of text now I am going to access T1 AP PRC out equal to pawan.in how it is going to print a value first of all and nextline see out B = 32 or 31 not be and function closed class also closed now watch this exam was actually we are available or declared in test one but we are accessing away from test to because of test 2 is declared as a friend to test one ok in this situation only we can access the test 1 data through the test for example now I am going to make a comment it is giving error here ok undefined symbol a undefined symbol be otherwise Test 2 August 1: Cola accessible text one column Columbia taxes work we are going to get that are the to avoid this you should have to introduce text to as a friend that’s why I am going to remove the comment catch 22 is the friend ok already without discuss that whenever we are having the friends they can access our data means our mobile everything ok like that is nothing but the friend class concept next here what happened we are declaring test one object inside the test to ok in this situation ok in this situation test one is called container class now it is the container class and test 2 is having what test one object that means what happened one class contains the object of another class now in the situation this class is called container class it is the existing class and this existing class object is declared in another class and that class is called container class and this relationship is called composition this relationship is called composition the soil composition is the process of composition is the process of declaring one class object in another class declaring object of one class within another class this one is called composition now with this what happened one class data is reused in another class 9 test 1 kb is reused interested to the soil composition close the concept of reusability ok the sirf friend class allows the concept of reusability means once again we are using guys listing date in another class ok but here it doesn’t tell us the extensibility it is a most important thing love generally in interviewer asking the question what is the difference between composition and inheritance Ok actually it is looking like inheritance concept what it is quite different why because in inheritance what happens we are we are deriving a class we are deriving a class from existing class that’s why the derived classes having both the base class properties and derived class properties ok observe the difference between composition and inheritance and composition what happening just we are declaring existing class object in another class due to this what happened that existing class data once again used in derived class means in container class that means it allows only what reusability concept and it never allows extensibility that means this properties are not added to test Una here test to is able to access the test 1 data but test 1 data is never added to text to button inheritance what happens from test one we are deriving the test this is what happened now the test to is having both test 1 data and its own data also for example here here we are there here xy are there now the test to data members a 20 and xy ok the Sahir the. Xy data member derived class ok the newly created class is called derived class and the derived class contains both the base class numbers as well as derived class number that’s why inheritance provides the concept of reusability and extensibility and this concept composition ok and to achieve this one we should how to declare this class as a friend to this class ok and this concept is called a composition next how to call this number functions of all this number now main function required ok later first of all we have to declare the objects test on 31 test 222 class objects are created when is from test 1 answer one is best to next year get a Member function is the member of this one that’s why I cannot get a b ok now when this function is called what happens SEO training working here when get heavy is called enter a b values the user is entering some data now there going to store and we have to print this data but print function is available in Test 2 and test 2 is what friend Funk friend class that’s why hair teeth do not put you through not put of which date I want to print test 1 EV data that’s why to access the test 1 EV data from Titu you should have to send you the day one object because of this function definition contains object as argument which class object test 1 class that’s why I hear put a b is having the one as the argument not even ok here it is the actual parameter is a formal parameter this one is going to print the day 1 and 31 way because of T2 is the friend of T1 OK then only it is possible next get Ch program finish

Speak Your Mind

*