I am trying to figure out how to fix my error listed in the title, I am getting the error on the implementation of my class name. The error is coming from my parkingControl.cpp 'ParkingControl parkingControlMenu;'. I have used this implementation fine before, but once I added a new main it stopped working. Below is my code.
Thank you for the help.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include "parkingControl.h"
/*
This module sets up the menu for the parking controller.
In here one can view the drawer with the money stored in
it and select a parking gate to enter from.
*/
usingnamespace std;
ParkingControl parkingControlMenu;
void ParkingControl::menuOverview()
{
ParkingLotGateA parkingLotA;
ParkingLotGateB parkingLotB;
ParkingLotGateC parkingLotC;
string dummy;
ifstream inputFile ("parking_account.txt");
inputFile >> dummy >> parkingControlMenu.total >> dummy >> parkingControlMenu.one >> dummy >> parkingControlMenu.five>>
dummy >> parkingControlMenu.ten >> dummy >> parkingControlMenu.twenty >> dummy >> parkingControlMenu.quarter;
}
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include "parkingControl.h"
usingnamespace std;
ParkingControl parkingMenuMain;
int main()
{
cout << "Welcome to ODU, Would you like to view our menu for parking?"<< endl;
cout << "Enter 1 to view menu or 0 to leave." << endl;
cin>>parkingMenuMain.parkingOption;
if (parkingMenuMain.parkingOption == 0)
{
exit(-1);
}
elseif (parkingMenuMain.parkingOption == 1)
{
parkingMenuMain.menuOverview();
}
return (0);
}
You should never #include C++ files (see line 7 of parkingControl.h). Keep in mind that #include is a glorified copy and paste and little else. In your particular case, parkingControl.cpp includes parkingControl.h... which includes parkingControl.cpp which again needs to include parkingControl.h, and so on. Did not see the header guards, sorry.
Also, please don't use namespaces in .h files. It pollutes the global namespace, and if someone for any reason doesn't want to have a usingnamespace std in their file (for example, to avoid name conflicts), then by including your header file they are forced to have it.
EDIT: Also, why are you making a global instance of ParkingControl in parkingControl.cpp?
> parkingControl.cpp includes parkingControl.h... which includes parkingControl.cpp
> which again needs to include parkingControl.h, and so on.
there are headers guards, so it would stop there.