Passing struct as argument into class?

Hey everyone. I'm having a problem passing my struct into my class member function. I feel it's redundant to have a structure in both the class and the main program. I'm reading from my book how to pass the structure into functions, and figured it should be the same to pass it into class functions, but I'm getting an error that I just cannot figure out. Here's a snippet of the code.

records.h
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
const int N_SIZE = 75,
		 A_SIZE = 75,
		 C_SIZE = 75,
		 S_SIZE = 30,
		 Z_SIZE = 14,
		 P_SIZE = 15,
		 D_SIZE = 14;

struct Info
{
	char name[N_SIZE],
		 addr[A_SIZE],
		 city[C_SIZE],
		 state[S_SIZE],
		 zip[Z_SIZE],
		 phone[P_SIZE],
		 dateLP[D_SIZE];

	float  acctBal;
};

//Records class performs manipulation of the information in the Info structure.
class Records
{
	public:
		Records() {}; //Sets default file to records.dat.********************
		void writeInfo(const Info &);
		string displayInfo();


records.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Records::writeInfo(const Info &entries)
{
	fstream recordsFile("records.dat", ios::out | ios::binary | ios::app);
		
	if (!recordsFile)
	{
		cout << "\nFile read error. The program will now terminate. \n";
		system("pause");
		exit(EXIT_FAILURE);
	}

	recordsFile.write(reinterpret_cast<char *>(&entries), sizeof(entries));

	recordsFile.close();
}


test.cpp (main program)
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
int main()
{
	Records records;
	Info customer;

	const int SIZE = 75; //Constant into to hold the size of the findName variable.
	long int position;   //Holds the read/write position of the file.

	char findName[SIZE],//Variable used for user-defined search key.
		 ans;			//Holds the user's input for navigating program.

	string input; //Gets input for each item from the user.
	
	cout << "Would you like to add a new entry? Y or N: ";
	cin >> ans;
	cin.ignore();

	while(toupper(ans) == 'Y')
	{
		cout << "\n****************NEW ENTRY*********************\n\n";

		cout << "NAME: ";
		getline(cin, input);
		
		
		cout << "ADDRESS: ";
		getline(cin, input);
		
		
		cout << "CITY: ";
		getline(cin, input);
		
		
		cout << "STATE: ";
		getline(cin, input);
		strcpy_s(customer.state, input.c_str());
		
		cout << "ZIP: ";
		getline(cin, input);
		strcpy_s(customer.zip, input.c_str());
		
		cout << "PHONE: ";
		getline(cin, input);
		strcpy_s(customer.phone, input.c_str());
		
		cout << "ACCOUNT BALANCE: $";
		cin >> customer.acctBal;
		cin.ignore();

		cout << "DATE OF LAST PAYMENT: ";
		getline(cin, input);
		strcpy_s(customer.dateLP, input.c_str());

		records.writeInfo(customer);


This is the error I'm getting :

1
2
3
records.cpp(9): error C2511: 'void Records::writeInfo(const Info &)' : overloaded member function not found in 'Records'

records.h(32) : see declaration of 'Records'



Any help would be appreciated. Thanks.
This might sound kind of silly but did you forget to to put a }; at the end of your class declaration? If you did do it, you didn't post it which is why I asked.

Additionally, I get an error with your line recordsFile.write(reinterpret_cast<char *>(&entries), sizeof(entries))

as you are trying to do this on a constant. Other than that, that was the only error I received.
Thanks! I didn't forget the };, Just didn't put the whole code =) I'll try to edit it according to your suggestion, that might be my problem! Thanks again.
I tried only using the reference parameter with the class function declaration and header.. Still got the same error. But, the error is occuring on that line.
Do you have more than one copy of records.h? If so, make sure that you are using the right one.

For example, you would get the error overloaded member function not found in 'Records' if the function is declared in the class as void writeInfo( /*const*/ Info &); // missing const

And:
1
2
// recordsFile.write(reinterpret_cast<char *>(&entries), sizeof(entries));
recordsFile.write( reinterpret_cast< const char * >(&entries), sizeof(entries) );
I'll try that, thanks!
Yes, I have more than one copy of records.h.... VS is confusing to me when it makes all these directories and I'm never sure which one it's using.
Prefer reading and writing plain text. http://www.cplusplus.com/forum/general/124733/#msg677461
Thanks! I will do. It seems like a pain to do binary.. I did it for the plain fact that I want to get it under my skin before I decide to stay away from it. First time ever using the binary open mode.. I have my program working, just not separated in classes yet and this code is still giving me problems even after the changes.
JLBorges, you are an awesome person! Turns out the different files were my problem. I deleted all the files that were in the directories and replaced them with the updated ones, and it fixed it! Thanks so much. I'm so happy...
Topic archived. No new replies allowed.