how to pass array of object in friend funcion?

  arguments, arrays, c++, friend-function, object

I am trying to pass array of object in friend function.
dut it shows undefined structure ‘Directory’.
And also can we use private data members in friend function.
Because if I create
Private:
char name[30];
It shows error
‘Directory::name’ not accessible.

#include<conio.h>
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
class Directory
{
  private:

  char phone_no[11];
      //    char name[30];
  public:
     char name[30];
     void input(char *n,char *no)
     {
        strcpy(name,n);
        strcpy(phone_no,no);
     }

  void  displayAll()
  {
     cout<<"nnName :"<<name<<"nPhone number :"<<phone_no;
  }
 void friend search(char *n,int i,Directory s[]);


  };

void search(char *n,int i,Directory s[])
{
int flag=0;
int j;
for(j=0;j>=i;j++)
{
    if( strcmp(s[j].name,n)==0)
    {
        flag=1;
        s[j].displayAll();
    }
    if(flag==0)
             cout<<"nnnot such name exists 
    in this directory";
   }

   };
   void main()
   {
     char n[30];
     char no[11];
     int ch;
     clrscr();
     int size;
    cout<<"Enter how many records you want to 
   create:";
   cin>>size;
   int i=-1;
   Directory *d=new Directory[size];
   while(ch!=0)
   {
    cout<<"n*****Menu*****nn";
    cout<<"Enter 0 for Exit:";
    cout<<"nEnter 1 for Adding records:";
    cout<<"nEnter 2 for Dispalying all 
records:";
    cout<<"nEnter 3 for Searching phone 
    number :";
    cout<<"nnEnter your choise:";
    cin>>ch;
    switch(ch)
    {
        case 0:
             exit(0);
             break;
        case 1:
            cout<<"nEnter contact details :";
            cout<<"nEnter name :";
            cin>>n;
            cout<<"nEnter phone number :";
            cin>>no;
            i++;
            d[i].input(n,no);
            break;
        case 2:
             int j;
             for(j=0;j<=i;j++)
            {
                    d[j].displayAll();

            }
             break;
        case 3:
            cout<<"nEnter name to search 
 phone number:";
            char n[30];
            cin>>n;
            search(n,i,d);
            break;

         default:
            cout<<"nEnter valid choise";
    }
 }
   getch();
 };

Please if any one knows how to pass array of object in friend function then help me.

Source: Windows Questions C++

LEAVE A COMMENT