Friend Function in C++

class A;

class B
int b;

void display(A x)
	cout<<x.a<<b;             //ERROR: 'a' is not a member of 'A'


class A
int a;

friend void B::display(A);


void main()
A a1;
B b1;

/END CODE************************/

the above code fetches errror… i have tried passing reference to th friend function but still the problem persists… :frowning: … ANYONE HAS ANY IDEA WHAT CAN I DO… !!!

Well, this code works


I just put the function definition for later ( outside the class ) and it worked ( well, it worked on my compiler )

Do not mind the errors on ideone as the code will work on your compiler ( I’m assuming you’re using TurboC++ )
I posted the ideone link because the code seems to be different when I post it directly here ( some strange characters are appearing instead of the code ).

Anyway, you should probably get a new IDE like codeBlocks, the programs you run on your current compiler is not C++ standard ( there is no conio.h in C++ standard, and instead of iostream.h, we use only iostream in the standard ) and will not be accepted on codechef.