latest Post

C++ part-2 (friend function )









So this is the second part of c++ series this is all about the friend function and its function.So if dont see our first part of this series the you first have to see it so you can study this step by step so you can make notes of it .We are also starting our c series very soon that will also helpful for you .


FRIEND FUNCTION:

-> These are the functions which can access private data of any class .

-> For calling friend function there is no need to create an object .         

-> These functions can access also protected data of a class .     

Now code....

#include<iostream.h>
#include<conio.h>
class abc
{
             int i;(the space before the line is given Tab)
             int count;
             public:
                       void input()
                       {
                                       cout<<"Enter any number:;
                                       cin>>i;
                                       count++;
                       }
                       friend void addition(abc,abc)
};                    
void addition(abc m,abc n)
                     cout<<"addition="<<m.i+n.i<<endl;
  (endl is used to give a line space afterthe line print when we run the program) 
}
void main()
{
                abc a,b;
                a.input();
                b.input();

                addition(a,b);
                getch();
}

If there is any problem regarding this article please right in the comment box.

PART 3 (reference variable)

About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment