Lecture Friend
Lecture Friend
Friend Class
Friend Class
Friend Function
• // Example program
• #include <iostream>
• #include <string>
• using namespace std;
• class car
• {
• private:
• int car_no;
• string car_name;
• public:
• car()
• {
• car_no=01;
• car_name="NEXA";
• cout<<car_no;
• cout<<car_name;
• }
•
• friend void bestcar(car &c);
•
• };
•
• void bestcar(car &c)
• {
• c.car_no=002;
• c.car_name="HONDA BRV";
• cout<<car_name;
• }
• int main()
• {
•
• car c;
• bestcar(c);
•
•
• }
Home Work
• One example for Friend Class.
What Is Inheritance?
• Provides a way to create a new class from an
existing class
• The new class is a specialized version of the
existing class