Friend function concept

am getting an error while executing this program the is as follows
1.member partition::parts is inaccessible
2.member partition::n is inaccessible
3.all private data members of class partition is also in accessible
]need solution and deep explanation on this concept

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<iostream>
using namespace std;

	class process
		{
		   private:
		   char name[5];
		   int mm_size,alloc,waste;

		   public:

		   void accept(int j)
			{
				cout<<"\nEnter the process name for process "<<j<<" ";
				cin>>name;
				cout<<"\nEnter memory required for process "<<name<<" ";
				cin>>mm_size;
			}
		    friend void calc(int k,process p[10],partition p2);
		   };

	 class partition
		{
		    private:
		    int t_mm,os_mm,user_mm;
		    int parts[10],n;

		    public:
		    void accept1()
			{
				cout<<"\nEnter the total memory available "<<" ";
				cin>>t_mm;
				cout<<"\nEnter total memory space "<<" ";
				cin>>os_mm;
				user_mm=t_mm-os_mm;
				cout<<"\nEnter the number of partitions "<<" ";
				cin>>n;
			}

		    void division()
			{
			    int i;
			    cout<<"\nCreate partitions"<<endl;
			    for(i=0;i<n;i++)
			       {
				  cout<<"\nAllocate memory to partition c"<<i+1;
				  cin>>parts[i];
			       }
			}
		    friend void calc(int k,process p[10],partition p2);
		};

	  void calculation(int k,process p[10],partition p2)
		{
		     int j,l;
		     cout<<"\nCreating first fit table ";
		     //partitioning and allocating memory
		     for(j=0,l=0;j<k,l<p2.n;j++,l++)
			{

			 z:  if(p[j].mm_size>p2.parts[l])
				{
				 p2.parts[l]=p2.parts[l]+p2.parts[l+1];
				 goto z;
				}
				else
				{
				   p[j].alloc=p2.parts[l];
				   p[j].waste=p2.parts[l]-p[j].alloct;
				   if(p[j].waste<0)
				   {p[j].waste=0;}
				}
			}
		  //displaying all parameters
		    cout<<"\nProcess name\tPartition no\tAllocated mem\tWaste ";
		    for(j=0,l=0;j<k,l<n;j++,l++)
		      {
			cout<<endl<<p[j].name<<"\t"<<l+1<<"\t"<<p[j].alloc<<"\t"<<p[j].waste<<endl;
		      }
		}

		int main()
		    {
			   process p3[10];partition p1;
			   int np,i;
			   cout<<"\nEnter the number of processes ";
			   cin>>np;
			   for(i=0;i<np;i++)
			   {
			     p3[i].accept(np);
			   }
			   p1.accept1();
			   p1.division();
			   calculation(np,p3,p1);
			   return 0;
		     }


could it be that your friend declaration up there (line 19) is "calc", but your function (lines 53 and 94) is actually called "calculation"?
still it is not working its saying member declared at lline 8 is inaccessible
Topic archived. No new replies allowed.