class className{
// Other Declarations
friend returnType functionName(arg list);
};
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
// Program to illustrate friend function
#include<iostream>
using namespace std;
class integer
{
int a, b;
public:
void set_value()
{
a=50;
b=30;
}
friend int mean(integer s); //declaration of friend function
};
int mean(integer s)
{
return int(s.a+s.b)/2.0; //friend function definition
}
int main()
{
integer c;
c.set_value();
cout<< "Mean value:" <<mean(c);
return 0;
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
class ClassB;
class ClassA {
// ClassB is a friend class of ClassA
friend class ClassB;
... .. ...
}
class ClassB {
... .. ...
}
Code Example |
---|
Cpp :: c++ string_t to string |
:: |
:: resharper fold if statement c+ |
:: C++ program to sizes of data types |
Cpp :: basic cpp |
:: power in c++ |
Cpp :: c++ thread wait fro 1 sec |
Cpp :: |
:: |
Cpp :: c++ garbage collection |
Cpp :: minheap cpp stl |
:: |
Cpp :: |
:: |
Cpp :: |
:: |
Cpp :: |
:: |
Cpp :: |
:: Maximum element in a map c++ |
Cpp :: compile and run cpp file on mac c++ |
Cpp :: |
:: |
:: c++ throw index out of bound |
:: |
Cpp :: |
:: |
:: C++ for vs while loops |
:: |
Cpp :: |