I am writing a data structure program to store inventory data in a file, then I need to read and display that information. The problem is, is I am getting an error that i can not find where the problem is. Can any one help? Any kind of help would be appreciated.
This is my error:
error LNK2019: unresolved external symbol "void __cdecl viewRec(class std::basic_fstream<char,struct std::char_traits<char> > &)" (?viewRec@@YAXAAV?$basic_fstream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main
1>H:\C++\stream objects\Chapter12\Debug\Chapter12.exe : fatal error LNK1120: 1 unresolved externals
const int DESC_SIZE = 51; // holds inventory description size
const int DATE_SIZE = 11; // holds date size
struct InventoryItem // inventory structure
{
char desc[DESC_SIZE]; // description holds 31 charaters
int quantity; // variable to hold quantity
double whlCost; // variable to hold wholesale cost
double rtlCost; // variable to hold retail cost
char date[DATE_SIZE]; // variable to hold date
};
int main()
{
void addRec(fstream &); // function prototype to add a record
void viewRec(fstream &); // function prototype to view a record
void chgRec(fstream &); // function prototype to change a record
{
long selection; // variable to hold menu selection
long recNum; // variable to hold the record number of the inventory item
You seem to have put the prototypes and definitions of your functions addRec, chgRec, ViewRec inside your main function. You cannot declare or define functions within other functions. You should move them outside of the main function.
Also, you should use [code]code[/code] tags to make your code more readable.
I am sorry, here is my code, with tags, i apologize for that. Again, I moved my int menu() out of my main, but it is still not working. This is my first C++ class and any help or suggestions on how to get through this stuff would be great. I normally don't struggle this much and for what ever reason, it just is not clicking.
int menu(); is inside of your inventory struct. This is fine but to define int menu, you need to use the scope operator "::".
Line 104 should be: int InventoryItem::menu()
Thank you, I made a few changes, but the int menu(); section is really raising a lot of problems. I am not sure if there is an easier way to handle this area. Now I am getting a stack overflow problem and a recursive error with in the int menu() area.
line 38: you already declared int menu() inside of struct InventoryItem. Also, you cannot declare functions inside of functions.
line 93: this should be selection = record.menu(); This way, you are accessing the function member of your record object.
line 105: int menu needs to be declared like: int InventoryItem::menu()
line 110: this should be in main. Right now, it is creating an infinite loop because every time menu() is called, it calls itself again before it has a chance to get to the return statement.