Error 'class' does not name a type.

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.

parkingControl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#ifndef PARKINGCONTROL_H_INCLUDED
#define PARKINGCONTROL_H_INCLUDED
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include "parkingControl.cpp"

using namespace std;

class ParkingControl
{
public:
    void menuOverview();
    int parkingOption;

private:
    int total, one, five, ten, twenty, quarter;
    int oneDollar = one*1;
    int fiveDollar = five*5;
    int tenDollar = ten*10;
    int twentyDollar = twenty*20;
    int quarterCents = quarter*.25;
    int totalCredits = oneDollar + fiveDollar + tenDollar
                       + twentyDollar + quarterCents;
    string line;
    string outFile;
};

#endif // PARKINGCONTROL_H_INCLUDED 


parkingControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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.
*/
using namespace 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;
}


parkingControlMain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include "parkingControl.h"

using namespace 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);
    }
    else if (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 using namespace 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?

-Albatross
Last edited on
Guessing why you have included a cpp
http://www.cplusplus.com/forum/general/113904/#msg622055

> 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.
Topic archived. No new replies allowed.