Hello everyone! I'm getting some weird errors and I have no idea why! Because the code looks fine to me, but maybe i'm overlooking somthing!
Its saying member function already defined or declared, and its highlighting int Record::menu(); and int Record::addRecord() but thats impossible becuase
if you look at my source code, it isn't!
here are the errors:
here is the code, animal.hCode:--------------------Configuration: Inventory Program with Linked Lists - Win32 Debug-------------------- Compiling... animal.cpp C:\unzipped\Inventory Program with Linked Lists\animal.cpp(7) : error C2535: 'int __thiscall Record::menu(void)' : member function already defined or declared c:\unzipped\inventory program with linked lists\animal.h(15) : see declaration of 'menu' C:\unzipped\Inventory Program with Linked Lists\animal.cpp(40) : error C2535: 'void __thiscall Record::createDB(void)' : member function already defined or declared c:\unzipped\inventory program with linked lists\animal.h(17) : see declaration of 'createDB' C:\unzipped\Inventory Program with Linked Lists\animal.cpp(58) : error C2535: 'void __thiscall Record::addRecord(void)' : member function already defined or declared c:\unzipped\inventory program with linked lists\animal.h(18) : see declaration of 'addRecord' C:\unzipped\Inventory Program with Linked Lists\animal.cpp(163) : fatal error C1004: unexpected end of file found main.cpp C:\unzipped\Inventory Program with Linked Lists\main.cpp(17) : fatal error C1004: unexpected end of file found Error executing cl.exe. Inventory Program with Linked Lists.exe - 5 error(s), 0 warning(s)
here is the code for, animal.cppPHP Code://animal.h
#include <iostream.h>
#include <stdio.h>
class Record
{
public:
Record() : pNext(0) //constructor
{
age[0] = 0; type[0] = 0; name[0] = 0;
health[0] = 0; sex[0] = 0, descript[0] = 0;
location[0] = 0; other[0] = 0;
}
int menu();
void Flush() { while (cin.get() != '\n') cin.get(); }
void createDB();
void addRecord();
void delRecord() { cout<<"delete record function\n"; } //working on
void display() { cout <<"display\n";
void search(){cout <<"search\n";} //working on
void quit() { exit(1);}
Record* pNext; //pNext is the pointer
private:
//data members
char age[5];
char type[30];
char name[30];
char health[100];
char sex[10];
char descript[100];
char location[100];
char other[100];
};
here is the code for, main.cppPHP Code://animal.cpp
//definition
#include "animal.h"
#include <fstream.h>
int Record::menu()
{
int choice;
cout<<".::--------------------Animal Menu---------------------::.\n";
cout<<"(1) Create a Database\n";
cout<<"(2) Add a new record\n";
cout<<"(3) Delete a record\n";
cout<<"(4) Search\n";
cout<<"(5) Return to Main Menu\n";
cout<<".::----------------------------------------------------::.\n";
cin >> choice;
switch(choice)
{
case 1: createDB();
break;
case 2: addRecord();
break;
case 3: delRecord();
break;
case 4: search();
break;
case 5: return 0;
break;
default: cout <<"Error. Please enter a choice, 1-4\n";
}
menu();
return 0;
}
void Record::createDB()
{
ofstream outfile("inventory.txt",ios::out);
if(!outfile)
{
cout<<"Error. Unable to create file\n";
}
else
{
cout<<"File successfully created\n";
outfile.close();
}
}
void Record::addRecord()
{
Record theHead; //new starting object, the head
Record *pNode = &theHead; //starting pointer, point to the head
ofstream fout("inventory.txt",ios::app);
Flush();
cout<<"Name: ";
cin.getline(pNode->name,30);
cout <<"Type: ";
cin.getline(pNode->type,30);
cout <<"Health: ";
cin.getline(pNode->health,100);
cout <<"Age: ";
cin.getline(pNode->age,5);
cout <<"Sex (M or F): ";
cin.getline(pNode->sex,10);
cout <<"Description: ";
cin.getline(pNode->descript,100);
cout <<"Location: " << endl;
cin.getline(pNode->location,100);
cout <<"Other: " << endl;
cin.getline(pNode->other,100);
while (pNode) {
fout << pNode->name << "#";
fout << pNode->type << "#";
fout << pNode->health << "#";
fout << pNode->age << "#";
fout << pNode->sex << "#";
fout << pNode->descript <<"#";
fout << pNode->location <<"#";
fout << pNode->other << endl;
pNode = pNode->pNext;
}
fout.close();
}
void intro()
{
cout<<"**********************************************************\n";
cout<<"| Welcome To Project FluX | \n";
cout<<"**********************************************************\n";
cout<<"\n\n";
}
//********** Main Menu *******
void mainMenu()
{
Record animal;
int choice;
cout<<".::---------------------Main Menu----------------------::.\n";
cout<<"(1) Create a Database\n";
cout<<"(2) Add a new record\n";
cout<<"(3) Delete a record\n";
cout<<"(4) Search\n";
cout<<"(5) Quit\n";
cout<<".::----------------------------------------------------::.\n";
cin >> choice;
switch(choice)
{
case 1: animal.menu();
mainMenu();
break;
case 2: animal.menu();
mainMenu();
break;
case 3: animal.menu();
mainMenu();
break;
case 4: animal.menu();
mainMenu();
break;
case 5: cout<<"thank you for using my program\n";
exit(1);
break;
default: cout <<"Error. Please enter a choice, 1-4\n";
}
mainMenu();
}
PHP Code://main.cpp
#include "animal.h"
//function prototypes
void intro();
void mainMenu();
int main()
{
intro();
mainMenu();
return 0;
}
Note: If i take out #include "animal.h" in the main.cpp i only get 4 errors, not 5. Maybe i need inclusion protection, like those #ifdef or #define,
but I don't know how to use them properly, any help would be great thanks!




Reply With Quote