Answers for "5 program code in c++ of friend function"

C++
0

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;
}
Posted by: Guest on April-20-2022

Browse Popular Code Answers by Language