**If i have friend function in class A and there is no member function in Class A.Then can i access class A useing that Friend function **
if not than how can access that class?
**If i have friend function in class A and there is no member function in Class A.Then can i access class A useing that Friend function **
if not than how can access that class?
Of course you can. For example
#include <iostream>
class A
{
private:
friend void f( A &a, int x )
{
a.x = x;
}
friend std::ostream & operator <<( std::ostream &os, const A &a );
int x = 10;
};
std::ostream & operator <<( std::ostream &os, const A &a )
{
return os << a.x;
}
int main()
{
A a;
std::cout << "a.x = " << a << '\n';
f( a, 20 );
std::cout << "a.x = " << a << '\n';
return 0;
}
The program output is
a.x = 10
a.x = 20