1 / 11

Friend Function In C With Example | C Tutorial For Beginners | C Tutorial

This presentation on Friend Function in C with example will help you learn the basics of friend function and how to access the private and protected members of a class. You will understand how to declare a friend function and look at its different features in this C tutorial for beginners video. Finally, you will look at a demo on using friend function in this C tutorial.<br><br>The below topics are covered in the Friend function in C presentation:<br><br>1. Why do we need Friend Function?<br>2. What is a Friend Function?<br>3. Declaration of Friend Function<br>4. What is a Friend class?<br>

Simplilearn
Télécharger la présentation

Friend Function In C With Example | C Tutorial For Beginners | C Tutorial

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What’s in it for you ? Why do we need a Friend function ? What is a Friend function in C++ ? Declaration of friend function What is a Friend class ? Features of friend function Advantages of friend function

  2. Why do we need Friend function? Friend functions are used when we want to access the private or protected members of the class without the objects. Friend function helps us avoid the case where the function must be a member of both of the classes to access them.. Friend function is also used to perform operator overloading.

  3. Click here to watch the video

  4. What is a Friend function in C++? A friend function is not a member function of a class and it is defined outside the class. The friend function can access private, public and protected members of the class

  5. Declaration of Friend function Friend function is declared using the friend keyword. Syntax: class class_name { friendreturn_typefunction_name(arguments); }; Here, friend is a keyword and function_name is the name of the function that is made friend of the class. The friend function definition is done outside the class and we don’t use friend keyword in the definition of friend function

  6. What is a Friend class? A Friend class is that class that can access the data members and member functions of a class to which it is a friend. If the classes are declared friends, then all the members functions of the class will be a friend function to the friend class.. Syntax: Class table; Class club { //code friend class table; }; Class table { //code; }

  7. Features of Friend function • A friend function can be invoked just like a normal function. • Friend function can be a member of another class. Its scope is not limited. • It can be declared in public, private or in protected parts as well. • The object of the class can be used as an argument for a friend function. • Friend function can access the members by using its object name and dot operator along with the member’s name.

  8. Advantages of Friend function • With the help of the friend function, we can access all the non-public members of the class. Advantages • It helps in operator overloading. • It allows us to share private information by a non-member function. • It allows us to generate more efficient code.

More Related