[..from Eckel c++]
Making a structure(or class) nested doesnot automatically give it access to private members.To accomplish this,we must follow a particular form, first declare (without defining ) the nested structure ,then declare it as s friend ,and finally define the structure.The structure definition must be separate from the friend declaration ,otherwise it would be seen by the compiler as a non-member.
Nested Friends c++ February 12, 2010
Friend c++ demonstration February 12, 2010
[..from C++ Eckel]
//Friend -demonstration
#include<iostream>
using namespace std;
struct X;
struct Y{
void f(X*);
};
struct X{
private:
int i;
public:
void initialize();
friend void g(X*,int);//global friend
friend void Y::f(X*);//struct member friend
friend struct Z; //entire struct is a friend
friend void h();
};
(more…)



Recent Comments