Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

5 program code in c++ of friend function

#include <iostream>
 
class A {
    int a;
 
public:
    A() { a = 0; }
 
    // global friend function
    friend void showA(A&);
};
 
void showA(A& x)
{
    // Since showA() is a friend, it can access
    // private members of A
    std::cout << "A::a=" << x.a;
}
 
int main()
{
    A a;
    showA(a);
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #program #code #friend #function
ADD COMMENT
Topic
Name
7+7 =