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
{
friendclass 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?
#ifndef AmulyaM//To avoid an inclusion loop
#define AmulyaM
#include <iostream>
#include "Joe_Encoder.h"
#include <fstream>
#include <string>
usingnamespace 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;
}
elsebreak;
}
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;
friendclass Ashwin;
friendclass Joe;
};
#endif
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.