My first time compiling as a project, and I am getting multiple definitions errors. I get 2 of them when I try to build the .exe file. I am using 3 files to build with, one is the driver, one header and implementation file.
I figure there is something wrong with this header file, but I am not sure what. I tried using #ifndef for the consts, and even for the whole thing, but that did nothing. I think it might be something in the first 3 consts, but I am not sure.
If the other 2 files are needed, I can add those, but they are pretty long.
const int rnum = 12;
const int snum = 3;
const int max_Weight = 6120;
//Class construction
class Cabin
{
public:
Cabin(int);
Cabin();
int cabArray[rnum][snum];
string dLocation;
string aLocation;
void fillArray();
void showCabin();
void reserveSeat(int);
void getACWeight();
void getForAftWt();
void swapSeats();
void getNumPass();
int numPass;
static int flt_Count;
//Static function to increment the number of flights
//### ONE LINE FUNCTION ALL DONE HERE ####
static int incFlights(){flt_Count++;}
//Member funtion to show the number of flights
//### ONE LINE FUNCTION ALL DONE HERE ####
int showFlights(){return flt_Count;}
private:
int flightNumber; //Holds the flight number
};
Is any of the methods being defined in a header or file that is included by more than one .cpp? Where is Cabin::flt_Count being defined?
Whenever you're asking about an error, post the error message. Otherwise all we can (usually) do is guess. Particularly since we don't have full access to the code.
F:/C++_CIS_173/Assign_8/cabin.o(.text+0x100):cabin.cpp: multiple definition of `Cabin::Cabin(int)'
F:/C++_CIS_173/Assign_8/Assign_8.o(.text+0x100):Assign_8.cpp: first defined here
F:/C++_CIS_173/Assign_8/cabin.o(.text+0x308):cabin.cpp: multiple definition of `Cabin::Cabin(int)'
F:/C++_CIS_173/Assign_8/Assign_8.o(.text+0x308):Assign_8.cpp: first defined here
collect2: ld returned 1 exit status
char exitWord; //Used to exit
int flightNum;
int pass_count; // passenger count for the flight.
//Init the static variable for the flt_Count to zero
int Cabin::flt_Count = 0;
//Initialize the overall cabin, flight 9999
Cabin cab_9999(9999);
//Begin Main
int main()
{
//Begin do-while loop for adding flights
do
{
//Ask the user for the flight num
cin >> flightNum;
//Create a Cabin object
Cabin cab_flightNum(flightNum);
//Increment the number of flights
//that have been created(STATIC FUNCTION)
Cabin::incFlights();
//Begin Do-While for each Cabin
do
{
cab_flightNum.showCabin();
cab_flightNum.reserveSeat(pass_count);
cab_flightNum.showCabin();
cab_flightNum.getACWeight();
cab_flightNum.getNumPass();
//Ask the user if they are done adding passengers to the flight
cin >> exitWord;
//End do-While loop for Cabin/flight
}while (exitWord != 'n');
//Now calculate cabin weight
cab_flightNum.getForAftWt();
//Ask user if they are done with program
cin >> exitWord;
//Check to see if user is quitting. If so, print total
//flights for the day.(MEMBER FUNCTION)
if ( exitWord == 'y')
{
cout << "There were " << cab_flightNum.showFlights()
<< " flights scheduled today.\n\n";
}
//End do-While loop for program
} while ( exitWord != 'y');
return 0;
}
If the implementation file is needed, I can add that as well, but it is pretty large.
I see now. I should put just the generic class definition in the header, and the overloaded ones in the implementation file. Thanks for all of the help!