Friend Functions
2 posters
Unix C++ :: UNIX CPP :: CPP :: Example Programs
Page 1 of 1
Friend Functions
- Code:
#include<iostream>
class Sample
{
int a;
public:
Sample(int a)
{
this->a=a;
}
int getA()
{
return a;
}
friend int disp(Sample s);
};
int disp(Sample s)
{
return s.a;
}
int main()
{
Sample s(10);
std::cout<<disp(s);
}
friend functions are not a part of class but can access all the members including private members of the class.
Friend Function
Friend function is a powerful tool for the programmers but i think too much of friend fucntion should not be used as it can hamper the data security of the program.
Vineet_More- Posts : 27
Points : 31
Join date : 2010-02-26
Unix C++ :: UNIX CPP :: CPP :: Example Programs
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|