|
-
Jun 20th, 2002, 01:54 PM
#1
Thread Starter
Registered User
member function already defined or declared? No idea!
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:
Code:
--------------------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, animal.h
PHP 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, animal.cpp
PHP 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();
}
here is the code for, main.cpp
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!
-
Jun 21st, 2002, 12:38 PM
#2
Frenzied Member
Wow you had a mess.
OK I think I fixed most of it. You will still get some errors about outfile, but I think I fixed everything else
PHP Code:
//animal.h
#ifndef __ANIMAL_H__ //<-------------------Changed
#define __ANIMAL_H__ //<-------------------Changed
#include <iostream> //<-------------------Changed
#include <stdio.h> //<-------------------Changed
#include <fstream> //<-------------------Changed
using namespace std; //<-------------------Changed
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";} //<-------------------Changed
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];
};
void intro(); //<-------------------Changed
void mainMenu(); //<-------------------Changed
#endif
//animal.cpp
//definition
#include "animal.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:<img src="/images/smilies/redface.gif" border="0" alt="">ut);
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();
}
//main.cpp
#include "animal.h"
//function prototypes
//void intro(); //<-------------------Changed
//void mainMenu(); //<-------------------Changed
int main()
{
intro();
mainMenu();
return 0;
}
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jun 21st, 2002, 07:15 PM
#3
Thread Starter
Registered User
thanks!
Thanks a ton! I also had to #include <stdlb.h> to get that file error working! and I really didn't need those protectors but i'll use them from now on!
-
Jun 23rd, 2002, 10:41 AM
#4
Frenzied Member
Those things are good to put in when ever you can. It won't always stop you from getting declaration errors, but its a good first step
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jul 9th, 2002, 02:34 AM
#5
I think you also need semicolons after the inline functions, but I may be mistaken.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jul 9th, 2002, 03:39 PM
#6
Frenzied Member
*looks at the date of the orginal post*
Umm...just getting to answering the questions on the board after some time away??
You dont need a ; at the end of a inline, its just like a normal function delc. just { }
MSVS 6, .NET & .NET 2003 Pro
I HATE MSDN with .NET & .NET 2003!!!
Check out my sites:
http://www.filthyhands.com
http://www.techno-coding.com

-
Jul 9th, 2002, 05:19 PM
#7
Can you please post the project zipped. I want to try it if you wan to.
-
Jul 10th, 2002, 08:22 PM
#8
I was away for some time. I just scanned all posts from my last one on.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|