Error with function with objects as parameters

Ok, so I am creating code for a group project in my class. All my group members made a header file with an object in it with their functions. One of the functions in my partner's code uses a data member of mine in the function, so she has the function parameter a object of my object. (This isn't the code but for example)

1
2
3
4
5
6
7
8
class B
{
friend class A;

void displayAthing(A object)
{
cout<<object.thing<<endl;
} 

I have this when I call the function in the cpp file

1
2
3
4
5
6
7
int main()
{
A object;
B b;
b.displayAthing(object);
return 0;
}

However, when I compile, it gives me an error that the function does not take 1 arguments, does anyone know what is wrong?
That shouldn't be the only error you're getting - you can't use an incomplete type on line 5 of class B like that.

http://www.cplusplus.com/forum/articles/10627/
I think I explained it incorrectly, here is my entire code (The names have no relevance, I changed them so my actual name isn't up here)

Header file #1
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
97
98
99
100
101
102
103
104
#ifndef AmulyaM//To avoid an inclusion loop
#define AmulyaM
#include <iostream>
#include "Joe_Encoder.h"
#include <fstream>
#include <string>
using namespace std;


class Amulya
{
public://Functions go here


	
void toAscii() //gets entered message, and converts to ascii
{

	cout << "Enter message: ";
	cin.getline(message,3001); //inputs the message

	row=0;

	while(1)
	{

		if(message[row]=='\0')
				break;
		ascii[row]=(int)message[row]; //turns it to ascii
		++row;
	}

	ascii[row]=0;
	ascii[row+1]=0; //turns the next two to 0, for safety

}

void multiplyKey(Joe joe) //multiplies the converted array by the key
{
	while(1)
	{
		if(row%3 != 0)
		{
			++row;
			continue;
		}
		else
			break;
	}

	int l=0;

	for(int i=0;i <row; ++i)
	{
		for(int j=0; j<3; ++j)
		{
			encrypt[i] += joe.key[i%3][j%3]*ascii[l+j]; //multiplying stuff
			/* Variable i keeps growing until it goes through all of the inputs, but for the key, it needs to stay the same.
			So, the modulus function is used. The variable j needs to be changed for the asciied array, but it stays the same
			for the key. So, l, which is equal to zero and increments by three whenever it goes through the loop, is added onto
			the j value for the asciied array. It shouldn't increment the first time though, so i has to be greater than 1*/
		}
	if(i%3==2 && i > 1)
		l+=3;
	}
}

void toFile(Joe myJoe)
{
	cout << "Enter file name: ";
	cin >> filename;

	ofstream OutFile (filename);

	for(int a=0; a<3; ++a)
	{
		for(int b=0; b<3; ++b)
		{
			OutFile << myJoe.EK[a][b];
			OutFile << " ";
		}
	    OutFile << endl;
	}

	for(int a=0; a<row; ++a)
	{
		OutFile << encrypt[a];
		OutFile << " ";
	}
	OutFile.close();
}

private://Variables go here

	char message[4000]; //original message
	int ascii[4000]; //message in ascii
	int encrypt[4000]; //ascii multiplied by key
	int row;
	string filename;
	friend class Ashwin;
	friend class Joe;

};
#endif 


Header file #2
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#ifndef JoeM //To avoid an inclusion loop.
#define JoeM
#include <iostream>
#include <ctime>
#include <cmath>
#include "Amulya.h"


using namespace std;

class Joe
{

public:
	
	/**********************************************/
	/*These are the functions of the code that are*/
	/*have been created by Joe and is for matrices*/
	/**********************************************/
	void generateKey()
	{
		srand(time(NULL));
		do
		{
		for (int j=0; j<3; ++j)
		{
			for (int i=0; i<3; ++i)
			{
				key[j][i]=rand()%27;
			}
		}
		det=(key[0][0]*key[1][1]*key[2][2])+(key[0][1]*key[1][2]*key[2][0])+(key[0][2]*key[1][0]*key[2][1])-(key[2][0]*key[1][1]*key[0][2])
			-(key[2][1]*key[1][2]*key[0][0])-(key[2][2]*key[1][0]*key[0][1]);
		} while(det==0);
		return;
	}

	//Generating the encrypted key to insert into the file
	void EKey()
	{
		for (int i=0;i<3;++i)
		{
			for (int j=0;j<3;++j)
			{
				EK[i][j]=((key[i][j]*key[i][j])+50)*7;
			}
		}
		return;
	}

	//Finding the determinate 
	void findDet()
	{
		det=(key[0][0]*key[1][1]*key[2][2])+(key[0][1]*key[1][2]*key[2][0])+(key[0][2]*key[1][0]*key[2][1])-(key[2][0]*key[1][1]*key[0][2])
			-(key[2][1]*key[1][2]*key[0][0])-(key[2][2]*key[1][0]*key[0][1]);		
	}

		//The first part of finding the inverse of a matrix
	void findInverseprt1()
	{
		N[0][0]=key[1][1]*key[2][2]-key[1][2]*key[2][1];
		N[0][1]=key[1][0]*key[2][2]-key[1][2]*key[2][0];
		N[0][2]=key[1][0]*key[2][1]-key[1][1]*key[2][0];
		N[1][0]=key[0][1]*key[2][2]-key[0][2]*key[2][1];
		N[1][1]=key[0][0]*key[2][2]-key[0][2]*key[2][0];
		N[1][2]=key[0][0]*key[2][1]-key[0][1]*key[2][0];
		N[2][0]=key[0][1]*key[1][2]-key[0][2]*key[1][1];
		N[2][1]=key[0][0]*key[1][2]-key[0][2]*key[1][0];
		N[2][2]=key[1][1]*key[0][0]-key[0][1]*key[1][0];
	return;
	}

	//Second part of finding the inverse of a matrix
	void findInverseprt2()
	{
		int count=0;
		for (int i=0; i<3; ++i)
		{
			for (int j=0; j<3; ++j)
			{
				if(count%2==1)
				{
					N[i][j]=N[i][j]*-1;
				}
				++count;
			}
			
		}
				
		Z[0][0]=N[0][0];
		Z[0][1]=N[1][0];
		Z[0][2]=N[2][0];
		Z[1][0]=N[0][1];
		Z[1][1]=N[1][1];
		Z[1][2]=N[2][1];
		Z[2][0]=N[0][2];
		Z[2][1]=N[2][1];
		Z[2][2]=N[2][2];

	}

	//Final part of finding the inverse of a matrix
	void findInverseprt3()
	{
		double x;
		x=1/det;
		for (int i=0; i<3; ++i)
		{
			for (int j=0; j<3; ++j)
			{
				IKey[i][j]=x*Z[i][j];
			}
		}

	}

	//Takes encoded key and decrypts it
	void decodeKey()
	{
		double z;
		for (int i=0;i<3;++i)
		{
			for (int j=0;j<3;++j)
			{
				z=(EK[i][j]/7)-50;
				key[i][j]=sqrt(z);
			}
		}
		return;
	}

	


	/******************************************/
	/*These are the driver and tester fuctions*/ 
	/******for the functions in part one*******/
	/******************************************/

	//The Driver for the generated key
	void keyDriver()
	{
		for(int i=0; i<3; ++i)
		{
			for (int j=0; j<3; ++j)
			{
				cout<<key[i][j]<<' ';
			}
		cout<<endl;
		}
	cout<<endl;
	return;
	}
	
	//Driver for the EK function
	void eKeyDriver()
	{
		for (int i=0;i<3;++i)
		{
			for (int j=0; j<3; ++j)
			{
				cout<<EK[i][j]<<' ';
			}
		cout<<endl;
		}
		cout<<endl;
		return;
	}
	
	//Driver for the det function
	void findDetDriver()
	{
		cout<<det<<endl<<endl;
	}
	
	//The driver of the inverse function
	void inverseDriver()
	{
		for (int i=0;i<3;++i)
		{
			for (int j=0; j<3; ++j)
			{
				cout<<IKey[i][j]<<' ';
			}
		cout<<endl;
		}
		cout<<endl;
	}

	//Checks Identity matrix

	void identityCheck()
	{
		for(int i=0; i<3; ++i)
		{
			for(int j=0;j<3; ++j)
			{
				for (int k=0; k<3; ++k)
				{
					Ident[i][j]=key[i][k]*IKey[k][j];
				}
			}
		}

		for(int i=0; i<3; ++i)
		{
			for(int j=0;j<3; ++j)
			{
				cout<<Ident[i][j]<<" ";
			}
			cout<<endl;
		}
	}

	/**************/
	/*Data Members*/
	/**************/

	private:
	double key[3][3];
	double EK[3][3];
	double N [3][3];
	double Z [3][3];
	double IKey[3][3];
	int Ident[3][3];
	double det;
	friend class Ashwin;
	friend class Amulya;

};
#endif 


And finally, the cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "Joe_Encoder.h"
#include "Amulya.h"
int main()
{
	Joe myJoe;
	Amulya amy; 
	myJoe.generateKey();
	myJoe.EKey();
	myJoe.findInverseprt1();
	myJoe.findInverseprt2();
	myJoe.findInverseprt3();
	amy.toAscii();
	amy.multiplyKey(myJoe); //Errors happen here
	amy.toFile(myJoe);
	return 0;
}
Last edited on
I am still a beginner to this but under Amulya's class she friends both Joe and Ashwin, but both are set to private, try moving them to public.
I think I figured it out.
class Amulya was trying to reference a class Joe that had not yet been compiled, I fixed it by putting them in the same header file.
Topic archived. No new replies allowed.