Write a program using a friend function, C/C++ Programming

Using a Friend

Using a friend function is quite easy. The following example explains a friend function to access members of two classes.

class Bclass;                                                        // Forward Declaration

class Aclass

 {

  public :

                                Aclass(int v)

                                 {

                                                Avar = v;

                                 }

 

friend int addup(Aclass &ac, Bclass &bc);

  private :

                                int Avar;

 };

class Bclass

 {

  public :

                                Bclass(int v)

                                 {

                                                Bvar = v;

                                 }

 

                                friend int addup(Aclass &ac, Bclass &bc);

  private :

int Bvar;

 

 };

int addup(Aclass &ac, Bclass &bc)

 {

                return( ac.Avar + bc.Bvar);

 }

void main()

 {

  Aclass aobj;

  Bclass bobj;

                  int total;

                                total = addup(aobj,bobj);

                 }

 

Posted Date: 6/28/2013 6:12:47 AM | Location : United States







Related Discussions:- Write a program using a friend function, Assignment Help, Ask Question on Write a program using a friend function, Get Answer, Expert's Help, Write a program using a friend function Discussions

Write discussion on Write a program using a friend function
Your posts are moderated
Related Questions
Dereferencing the Pointer this Sometimes a member function requires to make a copy of the invoking instance so that it can change the copy without affecting the original instan

You are setting up an information system for a DVD Rental Company called Box office. The new system need to hold information about customers and DVDs rentals, payments and fines. C

Write a C++ program that can be used to evaluate the credit worthiness of a client. The program reads the credit limit and the price and quantity of the item to be purchased by the

Project Description: Design and prepare software that can navigate a mobile robot using SLAM technique using vision sensor (camera). Skills required are C Programming, Engine

Demonstration using Moss Open Source Machine Translation Project Description: Moses is an open source Statistical Machine Translation System. I need someone to provide me a d

We started off taking about input, output, CPU and memory devices. Within C we need a method of storing large amounts of data in memory. We have used the idea of variables (pointer

Project Description: Not just like that though. I want a similar program that can scan through poker lobbys (pokerstars, full tilt, ongame and ipoker) and seat me to the left of

Question : (a) How does a structure differ from an array? (b) Describe how a structure differs from a union? (c) Declare a union called ‘clothes' which consists of the

how to do an array

#Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b.   #include float start_poi