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.
int main()
{
Records records;
Info customer;
constint SIZE = 75; //Constant into to hold the size of the findName variable.
longint 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'
I've checked that the definition and header are the same, and I do have a }; at the end of the class but only copy and pasted the portion of the code containing the error.
I am not sure if this will fix your code but line 12 in records.cpp must be recordsFile.write(reinterpret_cast<constchar *>(&entries), sizeof(entries)); You are trying to convert a const object to non-const char pointer.
Thanks! I think that was part of my problem. The other part is the way I had multiple copies of the same file in different directories.. and VS was using these files from different areas.. so some files weren't being updated as they should've been. I hate VS directories =(